views:

328

answers:

1

Hi, 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.

+1  A: 

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>
Mehrdad Afshari
Great, it works, thank you. I just want to ask, do you also know the solution to my second question?
Trimack
@Trimack: take a look at TraceSwitch class. It might help you turn off different categories of trace messages by means of a configuration option: http://msdn.microsoft.com/en-us/library/system.diagnostics.traceswitch.aspx
Mehrdad Afshari