Export (0) Print
Expand All

Enabling Application-Level Tracing

You can enable tracing for an entire application in the Web.config file in the application's root directory. By default, application-level tracing can be viewed only on the local Web server computer. You must set the localOnly attribute to false in the Web.config file to make application-level trace information visible from remote computers.

CAUTION   To help keep your Web application secure, use the remote trace capability only when you are developing or deploying your application. Be sure to disable it before you transfer your application onto production Web servers. To disable remote tracing, set the localOnly attribute to true in the Web.config file.

The following example shows an application trace configuration that collects trace information for up to 40 requests and allows browsers on computers other than the origin server to display the trace viewer.

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

When you enable tracing for an application, ASP.NET collects trace information for each request to the application, up to the maximum number of requests you specify. The default number of requests is 10. When the trace viewer reaches its request limit, the application stops storing trace requests.

Note   When you enable tracing for an entire application in the Web.config file, trace information is gathered and processed for each page in that application. To disable tracing for a particular page in the application, set the Trace attribute in that page's @ Page directive to false. Any TraceContext.Write or TraceContext.Warn statements that you include in a page's code are stored and returned to the trace viewer only.

If you want trace information to appear at the end of the page that it is associated with, set the pageOutput attribute in the tracing configuration section of the Web.config file to true. If you want tracing information to be displayed only in the trace viewer, set this attribute to false. If you enable application-level tracing, but you do not want trace information displayed for some pages of the application, use the @ Page directive to set the Trace attribute to false for those pages you do not want trace information displayed in.

For more information about configuring your ASP.NET application, see ASP.NET Configuration.

The following are all the attributes you can use to modify the behavior of application-level tracing.

Attribute Description
enabled true if tracing is enabled for the application; otherwise, false. The default is false.
pageOutput true if trace information is displayed both on an application's pages and in the .axd trace utility; otherwise, false. The default is false.
Note   Pages that have tracing enabled are not affected by this setting.
requestLimit Number of trace requests to store on the server. The default is 10.
traceMode Indicates whether trace information is displayed in the order in which it was processed (SortByTime) or alphabetically by user-defined category (SortByCategory). The default is SortByTime.
localOnly true if the trace viewer (Trace.axd) is available only on the host Web server; otherwise, false. The default is true.

To enable tracing for an application

  1. If you have not done so already, create a text file, name it Web.config, and save it to your application's root directory.
  2. Between the opening and closing tags of the <configuration> element, add the opening and closing tags of a <system.web> element.
  3. Between the <system.web> element tags, add a <trace> element, which is self-closing.
  4. In the <trace> element, declare the enabled attribute and set it to true.
  5. Declare other optional attributes to modify your application's trace behavior, as you want.

    For example, the following application trace configuration collects trace information for up to 40 requests and allows browsers on computers other than the origin server to display the trace viewer.

    <configuration>
     <system.web>
      <trace enabled="true" requestLimit="40" localOnly="false"/>
     </system.web>
    </configuration>
    
    Note   The ASP.NET configuration system is case-sensitive. All single-word configuration sections are lowercase, whereas sections or attributes that are concatenations of two words must be camel-cased. For example, requestLimit is a valid attribute name, but requestlimit causes a parser error.

Viewing Trace Information with the Trace Viewer

Once you have enabled tracing for your application, each page in the application will execute any trace statements that it contains when it is requested. You can view these statements and the additional trace information in the trace viewer by requesting Trace.axd from the root of your application directory.

Note   When you enable tracing for an application, you can view the trace statements, and additional information, in any page in the application by setting the pageOutput attribute to true in the Web.config file.

The trace viewer allows you to choose a specific request from the pages that have been requested from your application. The following screen shot shows a trace viewer that has had seven requests to its application since tracing was enabled.

Trace viewer

If multiple requests have arrived for an application that has tracing enabled, the trace viewer lists the requests in the order in which they were processed. The information on the opening page of the trace viewer includes the time of the request, the file requested, the status code of the request, the HTTP verb associated with the request, and a View Details link that allows you to see more detailed information about the request. The number of requests displayed will not exceed the requestLimit setting that you specified in the Web.config file.

To view trace details for a specific request

  1. Navigate to the trace viewer associated with your application.

    For example, if the URL for your application is http://localhost/myapplication, navigate to http://localhost/myapplication/trace.axd to view the trace statistics for that application.

  2. Select the View Details link for the request that you want to investigate.

    Once you have selected View Details, you view the same information that was appended to the page that had tracing enabled.

In some circumstances, you might want to remove all the requests stored in the trace viewer. Perhaps you want to track changes you made to files in your application, or you simply want to view information on other files than those associated with the currently displayed requests.

To clear requests from the trace viewer

  1. Navigate to the trace viewer associated with the application.
  2. Select the clear current trace link to remove all the requests stored in the trace viewer application.
    Note   The trace viewer tracks only requests made after you clear the log. Requests made after the request limit is reached and before you clear the log cannot be viewed.

See Also

TraceModeEnum Enumeration | ASP.NET Trace | ASP.NET Settings Schema | Enabling Tracing for a Page

Show:
© 2014 Microsoft