Example #1
0
        public static void Setup(ITelemetryCollector telemetryCollector, IShutdown shutdown)
        {
            void unhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
            {
                if (e.ExceptionObject is Exception ex)
                {
                    telemetryCollector.ReportException(ex, "Domain.UnhandledException");
                }
                else
                {
                    telemetryCollector.ReportException(
                        new Exception(e.ExceptionObject != null ? e.ExceptionObject.GetType().ToString() : "null exception object"),
                        "Domain.UnhandledException (custom exception)");
                }
            }

            AppDomain.CurrentDomain.UnhandledException += unhandledExceptionEventHandler;

            void unobservedTaskExceptionEventHandler(object sender, UnobservedTaskExceptionEventArgs e)
            {
                telemetryCollector.ReportException(e.Exception, "TaskScheduler.UnobservedTaskException");
            }

            TaskScheduler.UnobservedTaskException += unobservedTaskExceptionEventHandler;

            shutdown.Phase2Cleanup += (s, e) =>
            {
                AppDomain.CurrentDomain.UnhandledException -= unhandledExceptionEventHandler;
                TaskScheduler.UnobservedTaskException      -= unobservedTaskExceptionEventHandler;
            };
        }
Example #2
0
 public WinFormsUnhandledExceptionsReporter(ITelemetryCollector telemetryCollector) : base(telemetryCollector)
 {
     Application.ThreadException += (sender, e) =>
     {
         telemetryCollector.ReportException(e.Exception, "Application.ThreadException");
     };
 }
Example #3
0
 public static void Setup(ITelemetryCollector telemetryCollector)
 {
     Application.ThreadException += (sender, e) =>
     {
         telemetryCollector.ReportException(e.Exception, "Application.ThreadException");
     };
 }
 public UnhandledExceptionsReporter(ITelemetryCollector telemetryCollector)
 {
     AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
     {
         var ex = e.ExceptionObject as Exception;
         if (ex != null)
         {
             telemetryCollector.ReportException(ex, "Domain.UnhandledException");
         }
         else
         {
             telemetryCollector.ReportException(
                 new Exception(e.ExceptionObject != null ? e.ExceptionObject.GetType().ToString() : "null exception object"),
                 "Domain.UnhandledException (custom exception)");
         }
     };
     TaskScheduler.UnobservedTaskException += (sender, e) =>
     {
         telemetryCollector.ReportException(e.Exception, "TaskScheduler.UnobservedTaskException");
     };
 }