简体   繁体   中英

asp.net mvc exceptions tracing

I am trying to send an exception caught in Controller to trace.axd page, but I cant seem to figure it out. I have

<trace enabled="true" localOnly="false" mostRecent="true" pageOutput="false" />

in web.config, and my inteded reaction to an exception is

catch (Exception e)
{
    ViewData["error"] += "Is not number!";
    Trace.TraceError(e.ToString());
    Trace.TraceError(e.StackTrace);
    return View();
}

However, I can't find either of those strings anywhere on trace.axd page. So how to get them there?

Secondary, I want to ask, how should I turn off tracing not problematic (meaning those I do not personally send from some method) requests, since they just flood my trace and remove those occasional error reports sooner, than someone notices them.

Thanks in advance.

I guess your problem is that you are using the System.Diagnostics.Trace class instead of ASP.NET's tracing mechanism and it's not set to route trace messages to trace.axd . Try using Controller.HttpContext.Trace object for tracing.

Alternatively, try routing System.Diagnostics.Trace to ASP.NET tracing by adding the following snippet to web.config :

<system.diagnostics>
  <trace>
    <listeners>
       <add name="WebPageTraceListener" 
            type="System.Web.WebPageTraceListener, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
    </listeners>
  </trace>
</system.diagnostics>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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