-
-
Save mishrsud/9309e3f5b206e6aa6f1d38d14d77b1a7 to your computer and use it in GitHub Desktop.
UnhandledExceptionLogger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class UnhandledExceptionLogger | |
{ | |
public static void Install() | |
{ | |
var log = Log.ForContext(typeof(UnhandledExceptionLogger)); | |
AppDomain.CurrentDomain.UnhandledException += (s, e) => | |
{ | |
log.Fatal(e.ExceptionObject as Exception, "Unhandled exception caught at AppDomain boundary (terminating: {IsTerminating})", e.IsTerminating); | |
}; | |
TaskScheduler.UnobservedTaskException += (s, e) => | |
{ | |
e.SetObserved(); | |
log.Error(e.Exception, "Unobserved task exception detected, set observed"); | |
}; | |
Application.Current.DispatcherUnhandledException += (s, e) => | |
{ | |
Log.Error(e.Exception, "Unhandled exception on UI thread", e.Exception.Message); | |
e.Handled = true; | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment