title: How to trace Debug messages in ASP.net?
body: <p><strong>Short version:</strong> i've added</p>
  
  <pre><code> &lt;system.web&gt;
     &lt;system.diagnostics&gt;
        &lt;trace&gt;
           &lt;listeners&gt;
              &lt;add name="WebPageTraceListener" type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&gt;
           &lt;/listeners&gt;
        &lt;/trace&gt;
     &lt;/system.diagnostics&gt;
  </code></pre>
  
  <p>to my web-site's <strong>web.config</strong> file, but Visual Studio complains:</p>
  
  <blockquote>
    <p>Unrecognized configuration section system.web/system.diagnostics. </p>
  </blockquote>
  
  <p>How do i make Visual Studio (2010 (Professional (Windows 7 (64-bit)))) not complain?</p>
  
  <hr>
  
  <h2>Background</h2>
  
  <p>Microsoft explains that in ASP.net you use the <code>TraceContext.Warn</code> method to add tracing information to the trace output, e.g.:</p>
  
  <pre><code>Page.Trace.Warn("Starting up - da shield");
  </code></pre>
  
  <p>Tracing is then <a href="http://msdn.microsoft.com/en-us/library/bb386420.aspx" rel="nofollow noreferrer">enabled when you enable tracing</a>:</p>
  
  <pre><code>&lt;configuration&gt;
    &lt;system.web&gt;
      &lt;trace enabled="true" requestLimit="40" localOnly="false" /&gt;
    &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>or when you enable tracing:</p>
  
  <pre><code>&lt;%@ Page ... Trace="true" ... %&gt;
  </code></pre>
  
  <p>Tracing is then enabled on the bottom of the page:</p>
  
  <p><img src="https://i.stack.imgur.com/VBGXo.png" alt="enter image description here"></p>
  
  <hr>
  
  <h2>But what about System.Diagnostics tracing?</h2>
  
  <p>That's well and good for ASP.net code, but <em>business objects</em> don't use <strong><code>System.Web.UI.TraceContext</code></strong> for tracing, they use <code>System.Diagnostics.Trace</code>:</p>
  
  <pre><code>System.Diagnostics.Trace.TraceWarning("No giving up General Jar Jar. Yousa tink of someting");
  </code></pre>
  
  <p>Microsoft explains that you <strong>can</strong> route <code>Diagnostics</code> tracing through <code>Web</code> tracing using:</p>
  
  <blockquote>
    <h2><a href="http://msdn.microsoft.com/en-us/library/b0ectfxd.aspx" rel="nofollow noreferrer">Walkthrough: Integrating ASP.NET Tracing with System.Diagnostics Tracing</a></h2>
    
    <p><strong>Routing All Tracing Output to the Web Form</strong></p>
    
    <p>To route Trace messages to an ASP.NET Web page, you must add a WebPageTraceListener object. </p>
    
    <p>Place the following code in your Web.config file after the <strong>&lt;system.web&gt;</strong> section.</p>
  
  <pre><code>&lt;system.diagnostics&gt;
    &lt;trace&gt;
      &lt;listeners&gt;
         &lt;add name="WebPageTraceListener" 
              type="System.Web.WebPageTraceListener, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/&gt;
      &lt;/listeners&gt;
    &lt;/trace&gt;
  &lt;/system.diagnostics&gt;
  </code></pre>
  </blockquote>
  
  <p>Except that Visual Studio complains:</p>
  
  <blockquote>
    <p>Unrecognized configuration section system.web/system.diagnostics. </p>
  </blockquote>
  
  <p>Worse Than Failure?</p>