C# 如何在Silverlight 5中记录未处理的异常
我希望捕获并记录Silverlight 5应用程序中发生的未处理异常。我已经连接了Application.UnhandledException委托。问题是,在抛出异常之后,我能做什么,不能做什么?这个Silverlight应用程序运行在一个C++应用程序中,它承载WebMealMeX(IE的引擎),而这个主机正在执行外部函数。这就是Application.UnhandledException函数的外观:C# 如何在Silverlight 5中记录未处理的异常,c#,silverlight,logging,silverlight-5.0,unhandled-exception,C#,Silverlight,Logging,Silverlight 5.0,Unhandled Exception,我希望捕获并记录Silverlight 5应用程序中发生的未处理异常。我已经连接了Application.UnhandledException委托。问题是,在抛出异常之后,我能做什么,不能做什么?这个Silverlight应用程序运行在一个C++应用程序中,它承载WebMealMeX(IE的引擎),而这个主机正在执行外部函数。这就是Application.UnhandledException函数的外观: private void Application_UnhandledException(ob
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject;
// This is a reference to the
var external = External.Instance;
// loop through all the exceptions and call the hosts 'external' method so the
// host is able to write out the error to a local log file
while (external != null && ex != null)
{
external.LogException(ex.Message, ex.StackTrace);
ex = ex.InnerException;
}
// If the app is running outside of the debugger then report the exception using
// a ChildWindow control.
if (!System.Diagnostics.Debugger.IsAttached)
{
// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
ChildWindow errorWin = new ErrorWindow(e.ExceptionObject);
errorWin.Show();
}
}
目标是记录错误并保持应用程序运行。- 一个标准系统。诊断目标可使用 调试视图等
- 与NLog中类似的异步Web服务目标
- 具有延迟传输到服务器语义的隔离存储目标
看看这里:你试过了吗?完整的源代码示例和最终解决方案?