繁体   English   中英

如何在Silverlight 5中记录未处理的异常

[英]how to log Unhandled Exception in Silverlight 5

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

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

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

  • 标准的System.Diagnostics目标,用于使用DebugView等进行捕获。
  • 异步Web服务目标,类似于NLog中的目标。
  • 具有延迟传输到服务器语义的隔离存储目标

以下链接中的更多信息:

Silverlight日志记录框架和/或最佳实践

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM