Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

ASP.NET 2.0 Quickstart Tutorials

Application-level Trace Logging

In addition to the Page-level Trace funtionality, ASP.NET provides a way to enable trace output for an entire application. Enabling Trace at the application level has the effect of enabling Page-level Trace for every page within that application (provided there is no page-level directive to explicitly disable trace). When application-level tracing is enabled, the ASP.NET runtime also collects several additional statistics, such as the state of the control hierarchy, the contents of session and application state, the form and querystring input values, and other characteristics of request's execution. These statistics are collected for a specified number of requests as determined by the application's configuration file. To enable tracing for an application, place the following in the application's web.config file at the application root directory:
<configuration>
  <system.web>
    <trace enabled="true"/>
  </system.web>
</configuration>
Using the above configuration, each page in the application will run its page-level trace statements to be output in the client browser. To access the additional page statistics, request a specially-mapped "trace.axd" URL from the application root. For example, if the URL to your application is http://localhost/myapplication, you would request the URL http://localhost/myapplication/trace.axd to access the trace statistics for that application.



By default, trace information will be collected for up to 10 requests (you can use the "clear current trace" link to reset the request counter). The trace section of the configuration file also supports an attribute for controlling whether trace statements are output to the client browser, or whether they are only available from trace.axd. The attributes supported in the trace configuration section are listed in the table below:

ValueDescription
enabledSet to true | false, indicates whether Tracing is enabled for the application (default is false)
pageOutputSet to true | false, indicates whether trace information should be rendered at the end of each page - or only accessible via the trace.axd utility (default is false)
requestLimitNumber of trace requests to store on the server (default is 10)
traceModeSet to SortByTime | SortByCategory, indicates the display order for Trace messages (default is SortByTime)
localOnlySet to true | false, indicates whether Tracing is enabled for localhost users or for all users (default is true)

For example, the following configuration collects trace information for up to 40 requests, and prevents trace statements from being output to the requesting browser (provided there is no page-level directive to explicitly enable trace). The messages are displayed in order of category:
<configuration>
  <system.web>
    <trace
      enabled="true"
      traceMode="SortByCategory"
      requestLimit="40"
      pageOutput="false"
      localOnly="true"
    />
  </system.web>
</configuration>

Application Trace Request Details

After making a series of requests to the application, accessing trace.axd will list those requests in time-order. You can drill-down into the details for each request by selecting the "View Details" link.


The trace application presents the following detailed information for each request:
Request Detail
ValueDescription
Session IdThe Session Id for this request
Time of RequestThe time the request was made
Status CodeThe returned status code for this request
Request TypeGET | POST
Request EncodingEncoding for the request
Response EncodingEncoding for the response

Trace Information
ValueDescription
CategoryThe category for a Trace statement written to the TraceContext
MessageThe message string for this Trace statement
From First (s) Time in seconds from the first Trace statement
From Last (s)Time in seconds from the previous Trace statement

Control Hierarchy
ValueDescription
Control IDThe ID for the control
Type The fully qualified type of the control
Render SizeThe size of the control's rendering in bytes including children
ViewState SizeThe size of the control's viewstate in bytes excluding children

Session State
ValueDescription
KeyThe key for an object in Session State
TypeThe fully qualified type of the object
ValueThe value of the object

Application State
ValueDescription
KeyThe key for an object in Application State
TypeThe fully qualified type of the object
ValueThe value of the object

Cookies Collection
ValueDescription
NameThe name of the cookie
ValueThe value of the cookie, or sub-keys/values if multi-valued
SizeThe size of the cookie rendering in Bytes

Headers Collection
ValueDescription
NameThe name of the header
ValueThe value of the header

Form Collection
ValueDescription
NameThe name of the form variable
ValueThe value of the form variable

QueryString Collection
ValueDescription
NameThe name of the querystring variable
ValueThe value of the querystring variable

Server Variables
ValueDescription
NameThe name for the server variable
ValueTThe value of the server variable