Skip to content

Instantly share code, notes, and snippets.

@gkinsman
Created February 21, 2017 06:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gkinsman/38f859af32b80ed646bb642a17ad8d22 to your computer and use it in GitHub Desktop.
Save gkinsman/38f859af32b80ed646bb642a17ad8d22 to your computer and use it in GitHub Desktop.
UnhandledExceptionLogger
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