Created
February 21, 2017 06:24
-
-
Save gkinsman/38f859af32b80ed646bb642a17ad8d22 to your computer and use it in GitHub Desktop.
UnhandledExceptionLogger
This file contains 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