【问题标题】:How do I direct System.Diagnostics.Trace write messages to the ASP.NET trace viewer (trace.axd)?如何将 System.Diagnostics.Trace 写入消息到 ASP.NET 跟踪查看器 (trace.axd)?
【发布时间】:2015-10-22 09:21:17
【问题描述】:

我有一个部署在 Azure 实例上的 ASP.NET MVC 应用程序。

在这个应用程序中,我到处都有 System.Diagnostics.Trace 消息,包括这里(仅作为示例引用):

public class ExceptionLogFilterAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        System.Diagnostics.Trace
            .TraceError(string.Format("{0}\r\n\r\n", 
                        filterContext.Exception.ToString()));

        base.OnException(filterContext);
    }
}

在 web.config 中,我启用了跟踪。

但是,当我因为发生异常而被重定向到应用程序的默认错误页面后浏览到 trace.axd 时,我看不到任何我在上面的跟踪中写入的异常迹象。

【问题讨论】:

    标签: asp.net .net asp.net-mvc azure trace


    【解决方案1】:

    在您的 web.config 文件中添加此配置:

    <system.diagnostics>
       <trace>
          <listeners>
             <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, 
                Microsoft.WindowsAzure.Diagnostics, 
                Version=1.0.0.0, 
                Culture=neutral, 
                PublicKeyToken=31bf3856ad364e35"
                name="AzureDiagnostics">
                <filter type="" />
             </add>
          </listeners>
       </trace>
    </system.diagnostics>
    

    您可以在这里read more 了解它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-19
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 2019-11-25
      • 1970-01-01
      • 2020-09-13
      相关资源
      最近更新 更多