Skip to content

Instantly share code, notes, and snippets.

@jdhurst

jdhurst/Logger Secret

Created October 14, 2013 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdhurst/0872e8f339a132853c6d to your computer and use it in GitHub Desktop.
Save jdhurst/0872e8f339a132853c6d to your computer and use it in GitHub Desktop.
This is a slightly modified version of the class library 'Without User Interface', which comes with Red Gate's SmartAssembly [usually located in: /Red Gate/SmartAssembly 6/SDK/Exception Reporting/Without UI]. I've added 2 lines [22 & 23] which kill the application after logging the error.
using System;
using System.Security;
using SmartAssembly.SmartExceptionsCore;
namespace SmartAssemblyLogger
{
public class UnhandledExceptionHandlerWithoutUI : UnhandledExceptionHandler
{
protected override void OnSecurityException(SecurityExceptionEventArgs e)
{
e.ReportException = true;
}
protected override void OnReportException(ReportExceptionEventArgs e)
{
for (int i = 0; i < 3; i++)
{
if (e.SendReport()) break;
}
e.TryToContinue = false;
System.Diagnostics.Process proc = System.Diagnostics.Process.GetCurrentProcess();
proc.Kill();
}
protected override void OnFatalException(FatalExceptionEventArgs e)
{
throw e.FatalException;
}
public static bool AttachApp()
{
AttachExceptionHandler(new UnhandledExceptionHandlerWithoutUI());
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment