2014-02-14 39 views
0

我想捕获和记录在我的Silverlight 5应用程序中发生的未处理的异常。我已经连接了Application.UnhandledException委托。问题是,在抛出异常之后,我能做什么和不能做什么?这个Silverlight应用程序运行在托管WebControl(IE引擎)的C++应用程序中,并且该主机正在实现外部功能。因此,这是Application.UnhandledException的功能是什么样子:如何在Silverlight 5中记录未处理的异常

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(); 
    } 
} 

的目标是记录错误并保持应用程序的运行。

+0

看看这里:http://stackoverflow.com/questions/228723/silverlight-logging-framework-and-or-best-practices –

+0

你试过了吗?完整的源代码样本与最终解决方案? – Kiquenet

回答

2
  • 标准System.Diagnostics程序指定使用 DebugView中,等,以使得能够捕获
  • 一个类似于在NLOG异步Web服务目标。
  • 与递延转移到服务器语义的分离的存储目标
在以下链接

的更多信息:

Silverlight Logging framework and/or best practices