C# Global exception handling

Date: 2019-03-25
        private static void LogUnhandledExceptions()
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, args) =>
            {
                DomainPorts.LogMessageStore.StoreError($"Unhandled exception:\r\n{args?.ExceptionObject?.ToString()}");
#if DEBUG
                if (Debugger.IsAttached)
                    Debugger.Break();  
#endif
            };
            TaskScheduler.UnobservedTaskException += (sender, args) =>
            {
                DomainPorts.LogMessageStore.StoreError($"UnobservedTaskException:\r\n{args?.Exception?.ToString()}");
#if DEBUG
                if (Debugger.IsAttached)
                    Debugger.Break();  
#endif
            };
        }
20280cookie-checkC# Global exception handling