Unhandled Exception

Topics: Exception Handling Application Block, Logging Application Block
Jan 17, 2012 at 4:37 PM

I need to take notes through the logging of unhandled exceptions.
I think to a handler AppDomain.CurrentDomain.UnhandledException somehow tell the Enterprise Library logging system to record.
How can I do?

Jan 17, 2012 at 4:52 PM

I apologize.
The answer found.
Using the mechanism proposed in StockTraderRI.

        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            RunInReleaseMode();
        ...
        }

        private static void RunInReleaseMode()
        {
            AppDomain.CurrentDomain.UnhandledException += AppDomainUnhandledException;
            ...
        }

        private static void AppDomainUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            HandleException(e.ExceptionObject as Exception);
        }

        private static void HandleException(Exception ex)
        {
            if (ex == null)
                return;

            ExceptionPolicy.HandleException(ex, "Default Policy");
            ...message...
            Environment.Exit(1);
        }