【问题标题】:how to log Unhandled Exception in Silverlight 5如何在 Silverlight 5 中记录未处理的异常
【发布时间】:2014-02-14 20:51:02
【问题描述】:

我想捕获并记录在我的 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();
    }
}

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

【问题讨论】:

标签: c# silverlight logging silverlight-5.0 unhandled-exception


【解决方案1】:
  • 一个标准的 System.Diagnostics 目标,用于启用捕获使用 调试视图等
  • 类似于 NLog 中的异步 Web 服务目标。
  • 具有延迟传输到服务器语义的隔离存储目标

更多信息请点击以下链接:

Silverlight Logging framework and/or best practices

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-23
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    • 1970-01-01
    相关资源
    最近更新 更多