Procházet zdrojové kódy

Log AppDomain unhandled exceptions

Antony Male před 10 roky
rodič
revize
de38057ff2
1 změnil soubory, kde provedl 9 přidání a 0 odebrání
  1. 9 0
      src/SyncTrayzor/Bootstrapper.cs

+ 9 - 0
src/SyncTrayzor/Bootstrapper.cs

@@ -128,6 +128,8 @@ namespace SyncTrayzor
                 Process.GetCurrentProcess().Kill();
             };
 
+            AppDomain.CurrentDomain.UnhandledException += (o, e) => OnAppDomainUnhandledException(e);
+
             MessageBoxViewModel.ButtonLabels = new Dictionary<MessageBoxResult, string>()
             {
                 { MessageBoxResult.Cancel, Resources.Generic_Dialog_Cancel },
@@ -166,6 +168,13 @@ namespace SyncTrayzor
             logger.Debug("SyncTrazor version {0} ({1}) started at {2}", assembly.FullVersion, assembly.ProcessorArchitecture, assembly.Location);
         }
 
+        private void OnAppDomainUnhandledException(UnhandledExceptionEventArgs e)
+        {
+            // Testing has indicated that this and OnUnhandledException won't be called at the same time
+            var logger = LogManager.GetCurrentClassLogger();
+            logger.Error(String.Format("An unhandled AppDomain exception occurred. Terminating: {0}", e.IsTerminating), e.ExceptionObject as Exception);
+        }
+
         protected override void OnUnhandledException(DispatcherUnhandledExceptionEventArgs e)
         {
             var logger = LogManager.GetCurrentClassLogger();