Skip to content

Instantly share code, notes, and snippets.

@hastarin
Created December 23, 2017 23:10
Show Gist options
  • Save hastarin/452667b593253638f7704f74cd2b2cba to your computer and use it in GitHub Desktop.
Save hastarin/452667b593253638f7704f74cd2b2cba to your computer and use it in GitHub Desktop.
Unhandled Exception Logging
// Hook in App.OnStartup
AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
private static void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (!e.IsTerminating)
{
return;
}
var message = "Unhandled exception:" + Environment.NewLine + e.ExceptionObject;
// NOTE: Not needed since we aren't using WCF but leaving here for reference
//if (e.ExceptionObject is WebFaultException<string>)
//{
// var wfe = e.ExceptionObject as WebFaultException<string>;
// message += Environment.NewLine + "WebFaultException details:";
// message += Environment.NewLine + wfe.Message;
// message += Environment.NewLine + wfe.Detail;
// message += Environment.NewLine + wfe.InnerException;
//}
Log.Fatal(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment