我希望获得一个崩溃报告,因此我在App.xaml.cs中注册了UnhandledException事件,代码如下。但是出现了两个问题:
- 有时候异常没有调用堆栈
- 有时候进程终止之前我没有足够的时间将日志记录到文件中。
有什么建议吗?
this.UnhandledException += App_UnhandledException;
private async void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
if (!hasHandledUnhandledException)
{
e.Handled = true;
_logger.Error("Unhandle exception - message = {0}\n StackTrace = {1}", e.Exception.Message, e.Exception.StackTrace);
await CrashHandler.ReportExceptionAsync(e.Exception.Message, e.Exception.StackTrace);
hasHandledUnhandledException = true;
throw e.Exception;
}
}
e.Exception.ToString()
而不是将消息与堆栈跟踪分开。 - Panagiotis KanavosCrashHandler.ReportExceptionAsync
实际上做了什么。我在考虑与UI相关的事情。 - Kevin Gosseawait
时,该方法会返回,并且你的应用程序将被终止。 - Kevin Gosse