Log unhandled exceptions

This commit is contained in:
Scott_NZ
2013-05-02 23:45:05 +12:00
parent 6da0db0035
commit da0b4ecd3b

View File

@@ -12,8 +12,8 @@ using System;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Windows.Forms;
using System.Text; using System.Text;
using System.Windows.Forms;
namespace OpenRA namespace OpenRA
{ {
@@ -31,18 +31,25 @@ namespace OpenRA
return; return;
} }
AppDomain.CurrentDomain.UnhandledException += (_, e) => LogException((Exception)e.ExceptionObject);
try try
{ {
Run(args); Run(args);
} }
catch (Exception e) catch (Exception e)
{
LogException(e);
}
}
static void LogException(Exception e)
{ {
Log.AddChannel("exception", "exception.log"); Log.AddChannel("exception", "exception.log");
var rpt = BuildExceptionReport(e).ToString(); var rpt = BuildExceptionReport(e).ToString();
Log.Write("exception", "{0}", rpt); Log.Write("exception", "{0}", rpt);
Console.Error.WriteLine(rpt); Console.Error.WriteLine(rpt);
} }
}
static StringBuilder BuildExceptionReport(Exception e) static StringBuilder BuildExceptionReport(Exception e)
{ {