Compartilhar via


Application-Level ASP.NET Tracing Overview

You can configure individual pages to display trace information. Alternatively, you can configure the application's Web.config file so that all pages display trace information unless the page explicitly disables tracing. Setting application-level tracing is useful because you do not need to make changes to individual pages to enable and disable it.

You enable application-level tracing using the trace element in the Web.config file. When you enable application-level tracing, 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. By default, when the trace viewer reaches its request limit, the application stops storing trace requests. You can configure tracing to store either oldest tracing data (discarding newer items) or the most recent trace information (discarding older items).

NoteNote

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 override the application-wide settings, set the Trace attribute in that page's @ Page directive to false. Any Write or Warn statements that you include in a page's code are stored and returned to the trace viewer only.

Viewing Trace Information

As with page tracing generally, you can view trace information at the bottom of individual pages. Alternatively, you can use the trace viewer (Trace.axd) to view trace information collected and cached by ASP.NET when tracing is enabled.

If you want trace information to appear at the end of the page that it is associated with, you can set the trace element's PageOutput attribute to true. If you enable application-level tracing, but you do not want trace information displayed for some pages, you can set the Trace attribute in those pages' @ Page directive to false. For more information about configuring your ASP.NET application, see ASP.NET Configuration Overview.

By default, application-level tracing can be viewed only on the local Web server computer. To make application-level trace information visible from remote computers, you can set the trace element's LocalOnly attribute to false.

NoteNote

To help keep your Web application secure, use the remote tracing capability only when you are developing or deploying your application. Be sure to disable it before you transfer your application to production Web servers by setting 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 server to display the trace viewer.

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

Trace Configuration Attributes

The following table shows the attributes you can use to modify the behavior of application-level tracing in the trace element of the Web.config file.

Attribute Description

enabled

true to enable tracing for the application; otherwise, false. The default is false. You can override this setting for individual pages by setting the Trace attribute in those pages' @ Page directive to true or false.

pageOutput

true to display trace both in pages and in the trace viewer (Trace.axd); otherwise, false. The default is false.

NoteNote
Individual pages that have tracing enabled are not affected by this setting.

RequestLimit

The number of trace requests to store on the server. The default is 10.

traceMode

The order in which trace information is displayed. Set to SortByTime to sort by the order in which information was processed. Set to SortByCategory to sort alphabetically by user-defined category. The default is SortByTime.

localOnly

true to make the trace viewer (Trace.axd) available only on the host Web server; otherwise, false. The default is true.

mostRecent

true to display the most recent trace information as tracing output; otherwise, false, which indicates that once the requestLimit value is exceeded, new requests are not stored. The default is false.

NoteNote
Tracing data that exceeds the limit defined by the requestLimit attribute is discarded in favor of the most recent data only when mostRecent is true.

See Also

Tasks

How to: Enable Tracing for an ASP.NET Application