2

Short version: i've added

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

to my web-site's web.config file, but Visual Studio complains:

Unrecognized configuration section system.web/system.diagnostics.

How do i make Visual Studio (2010 (Professional (Windows 7 (64-bit)))) not complain?


Background

Microsoft explains that in ASP.net you use the TraceContext.Warn method to add tracing information to the trace output, e.g.:

Page.Trace.Warn("Starting up - da shield");

Tracing is then enabled when you enable tracing:

<configuration>
  <system.web>
    <trace enabled="true" requestLimit="40" localOnly="false" />
  </system.web>
</configuration>

or when you enable tracing:

<%@ Page ... Trace="true" ... %>

Tracing is then enabled on the bottom of the page:

enter image description here


But what about System.Diagnostics tracing?

That's well and good for ASP.net code, but business objects don't use System.Web.UI.TraceContext for tracing, they use System.Diagnostics.Trace:

System.Diagnostics.Trace.TraceWarning("No giving up General Jar Jar. Yousa tink of someting");

Microsoft explains that you can route Diagnostics tracing through Web tracing using:

Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing

Routing All Tracing Output to the Web Form

To route Trace messages to an ASP.NET Web page, you must add a WebPageTraceListener object.

Place the following code in your Web.config file after the <system.web> section.

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

Except that Visual Studio complains:

Unrecognized configuration section system.web/system.diagnostics.

Worse Than Failure?

0

1 Answer 1

3

<system.diagnostics> should be the child of <configuration> not <system.web>, so something like:

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

Hope I understood the issue right and this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

It stops error Visual Studio was throwing (that was my bad, i read after system.web to be after <system.web> rather than after </system.web>). Unfortunately, it turns out that ASP.net web-sites do not support the WebPageTraceListener
I guess you're left to the plain old txt file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.