Trimack
Trimack

Reputation: 4233

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.

Upvotes: 4

Views: 1930

Answers (1)

Mehrdad Afshari
Mehrdad Afshari

Reputation: 422280

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>

Upvotes: 4

Related Questions