Skip to content

Instantly share code, notes, and snippets.

@RdlP
Created January 3, 2017 16:07
Show Gist options
  • Select an option

  • Save RdlP/fc7f305d895ade756cad695f1e1851e3 to your computer and use it in GitHub Desktop.

Select an option

Save RdlP/fc7f305d895ade756cad695f1e1851e3 to your computer and use it in GitHub Desktop.
public MainWindow()
{
InitializeComponent();
// Logea las excepciones no controladas.
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(unhandledException);
}
static void unhandledException(object sender, UnhandledExceptionEventArgs args)
{
Exception e = (Exception)args.ExceptionObject;
Console.WriteLine("MyHandler caught : " + e.Message);
Console.WriteLine("Runtime terminating: {0}", args.IsTerminating);
Console.WriteLine("StackTrace: {0}", e.StackTrace);
using (System.IO.StreamWriter file = new System.IO.StreamWriter(Directory.GetCurrentDirectory() + @"\log.txt", true))
{
DateTimeOffset date = DateTimeOffset.Now;
file.WriteLine("========={0:MM/dd/yy H:mm:ss zzz}=========", date);
file.WriteLine(e.Message);
file.WriteLine(args.IsTerminating);
file.WriteLine(e.StackTrace);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment