Why don't trace listeners log custom handler traffic?

£可爱£侵袭症+ 提交于 2020-01-24 05:43:31

问题


I have a custom handler like this,

public class Handler : IHttpHandler
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}

Why does this not work?

<system.diagnostics>
  <sources>
    <source name="System.Web" switchValue="All" propagateActivity="true">
      <listeners>
        <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Traces_Documents.svclog" />
      </listeners>
    </source>
  </sources>
</system.diagnostics>

When that is in the web.config it does nothing when I call the handler. No logging etc.

I have previously used the same trace listener on the System.ServiceModel namespace with a WCF service, and that worked.


回答1:


Do you have tracing enabled?

<system.web>
    <trace enabled="true" writeToDiagnosticsTrace="true" />
</system.web>

Also, what version of the framework / IIS are you using?

See the DnrTV episode w/ Steve Smith which has good information on Asp.Net Tracing.



来源:https://stackoverflow.com/questions/6104103/why-dont-trace-listeners-log-custom-handler-traffic

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!