Tracing in .Net 2.0



Tracing is a new feature in .Net 2.0 that helps the user to view the different steps that have occurred in execution of a single ASP.Net Page at run time. Tracing information helps you to investigate errors or unwanted results when ASP.Net processes a page request.

By default, tracing is disabled so if you want to view the tracing information you have to enable the tracing.

Tracing can be one of two types Page Level Tracing and Application Level Tracing.

Page Level Tracing:

Gives information about a particular page.

To enable the page level tracing Add "Trace=true" in the Page directive of an ASP.Net Page:

<%@ Page Trace="true" %>

Another attribute that you can use here is TraceMode.

Set TraceMode to SortByTime to sort the information in the order of execution.

Set TraceMode to SortByCategory to sort the information by categories.

<%@ Page Language="VB" Trace="True" TraceMode="SortByCategory" %>

Application Level Tracing:

Gives information about the whole application.

Application level tracing can be enabled in the web.config file by using the trace element inside the system.web tag.

<configuration>
<system.web>
<trace enabled="true" />
</system.web>
</configuration>

Other elements that can be used are:

pageOutput-> Set this element to true if you want to display trace information at the end of the page; set this element to false if you want to display trace information in TraceViewer.

requestLimit-> A number that indicates for how many requests trace information is required.

Note: A Trace attribute in a Page directive overrides the trace attribute in web.config file.

How to view trace information with trace viewer

To do this, tracing should be enabled in the web.config file.

  1. Navigate to trace.axd in the root of your application.

    For example, if the URL for your application is http://localhost/SampleApplication, navigate to http://localhost/SampleApplication/trace.axd to view the trace information for that application.
     
  2. Select the View Details link for the request that you want to investigate.

    Tracking1.gif

Disadvantages of using Tracing

Tracing displays sensitive information, such as values of server variables, and can therefore cause security vulnerabilities. So be sure to disable the tracing before deploying your application to a production server.