Microsoft KB Archive/306731

= INFO: New Tracing Feature in ASP.NET =

Article ID: 306731

Article Last Modified on 1/20/2004

-

APPLIES TO


 * Microsoft ASP.NET 1.1
 * Microsoft ASP.NET 1.0
 * Microsoft Visual Basic .NET 2003 Standard Edition
 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition
 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition

-



This article was previously published under Q306731



SUMMARY
This article provides information about the new tracing feature in ASP.NET. This article also describes how to configure this tracing feature.



MORE INFORMATION
The tracing feature allows you to track the execution of an application and view the results. You can enable tracing at the page level or the application level.

Enable Tracing at the Page Level
When you enable tracing at the page level, the trace output is added to the bottom of the page. The following code sample demonstrates how to enable tracing at the page level:

Visual Basic .NET <%@Page Language=&quot;vb&quot; Trace=&quot;true&quot;%>  Public Function TracingTest(strNow as String) as String Trace.Write(&quot;Now Value in the function&quot;, now) return &quot;The time is: &quot; & strNow end Function

TracingTest result: <%=TracingTest(Now)%> Visual C# .NET <%@ Page Language=&quot;c#&quot; Trace=&quot;true&quot;%>  public string TracingTest(string strNow) {   Trace.Write(&quot;Now Value in the function&quot;,DateTime.Now.ToString); return &quot;The Time is: &quot; + strNow; }

Tracing Test Results: <%=TracingTest(DateTime.Now.ToString)%> Visual J# .NET <%@ Page Language=&quot;VJ#&quot; Trace=&quot;true&quot;%> <%@ import namespace = &quot;System.Diagnostics&quot; %> <%@ import namespace = &quot;System&quot; %>



public System.String TracingTest(System.String strNow) {   Trace.Write(&quot;Now Value in the function&quot;,DateTime.get_Now.ToString); return &quot;The Time is: &quot; + strNow; } Tracing Test Results: <%=TracingTest(DateTime.get_Now.ToString)%> When you run this page, both of the results from the function are written to the browser. You also see the information that tracing returns.

To remove the trace information, set the Trace attribute of the @ Page directive to false. You do not need to remove the Trace.Write statement. Notice that this is the TraceContext class, not the Trace class.

To enable tracing at the page level in Microsoft Visual Studio .NET, you can also set the trace property of the document to true in the Properties window.

Enable Tracing at the Application Level
To enable tracing at the application level, use the Web.config file. The following code sample demonstrates how to configure tracing at the application level in the Web.config file:    When you enable tracing at the application level, you can use the pageOutput attribute to specify whether the trace output is displayed at the page level. If you set pageOutput to true, the output displays the same results as if you set the Trace attribute of the @ Page directive at the top of the page to true.

NOTE: The trace setting at the page level overrides the trace setting at the application level.

