4. Application-Level Tracing
Application-level tracing allows you to enable
tracing for an entire application. However, the tracing information
won't be displayed in the page. Instead, it will be collected and
stored in memory for a short amount of time. You can review the
recently traced information by requesting a special URL.
Application-level tracing provides several advantages. The tracing
information won't be mangled by the formatting and layout in your web
page, you can compare trace information from different requests, and
you can review the trace information that's recorded for someone else's
request.
To enable application-level tracing, you need to modify settings in the web.config file, as shown here:
<configuration>
<system.web>
<trace enabled="true" requestLimit="10" pageOutput="false" />
</system.web>
</configuration>
Table 1. Tracing Options
Attribute | Values | Description |
---|
enabled | true, false | Turns application-level tracing on or off. |
requestLimit | Any integer (for example, 10) | Stores
tracing information for a maximum number of HTTP requests. Unlike
page-level tracing, this allows you to collect a batch of information
from multiple requests. When the maximum is reached, ASP.NET may
discard the information from the oldest request (which is the default
behavior) or the information from the new request, depending on the
mostRecent setting. |
pageOutput | true, false | Determines
whether tracing information will be displayed on the page (as it is
with page-level tracing). If you choose false, you'll still be able to
view the collected information by requesting trace.axd from the virtual
directory where your application is running. |
traceMode | SortByTime, SortByCategory | Determines the sort order of trace messages. The default is SortByTime. |
localOnly | true, false | Determines
whether tracing information will be shown only to local clients
(clients using the same computer) or can be shown to remote clients as
well. By default, this is true and remote clients cannot see tracing
information. |
mostRecent | true, false | Keeps
only the most recent trace messages if true. When the requestLimit
maximum is reached, the information for the oldest request is abandoned
every time a new request is received. If false (the default), ASP.NET
stops collecting new trace messages when the limit is reached. |
To view tracing information, you request the
trace.axd file in the web application's root directory. This file
doesn't actually exist; instead, ASP.NET automatically intercepts the
request and interprets it as a request for the tracing information. It
will then list the most recent collected requests, provided you're
making the request from the local machine or have enabled remote
tracing (see Figure 14).
NOTE
Sometimes when requesting trace.axd from Visual
Studio's test web server, you may not see the most recent traced
requests. In this situation, click the browser's Refresh button to get
an updated list.
You can see the detailed information for any request
by clicking the View Details link. This provides a useful way to store
tracing information for a short period of time and allows you to review
it without needing to see the actual pages (see Figure 15).