Recipe 10.2 Uncovering Problems Application Wide

     

10.2.1 Problem

You want to find the sources of problems at any point in an application, but you don't want to have to change every page to do so, nor do you want to disrupt the output of your application pages.

10.2.2 Solution

Enable application-level tracing in the application web.config file and then view the AXD application trace log for your application.

  1. Locate the web.config file in the root directory of your application (or create one if it does not already exist).

  2. Enable application-level tracing by adding a <trace> element to the <system.web> section of web.config and setting its enabled attribute to " true ":

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

  3. View the application trace log by browsing to the trace.axd page from the application root, like this:

    http://localhost/<your application name >/trace.axd

Figure 10-2 shows some sample trace log output.

Figure 10-2. Application-level tracing output (trace.axd)
figs/ancb_1002.gif

10.2.3 Discussion

By adding a <trace> element to web.config and setting its enabled attribute to " true ", you can activate application-level tracing.

 <trace enabled="true" /> 

What then happens is that ASP.NET collects trace information for each HTTP request to the application and directs it to the application trace log. You can view the application trace log in the trace viewer. To view the trace viewer, request trace.axd from the root of your application directory:

http://localhost/<your application name>/trace.axd

trace.axd is not an actual page but rather a special URL that is intercepted by ASP.NET. In actuality, trace.axd is an HTTP handler, the equivalent of an ISAPI extension. Chapter 17 provides recipes on how to create your own HTTP handlers.


What trace.axd actually shows you is a sequential listing of the HTTP requests processed by your application, as shown in Figure 10-2.

Here are some of the more commonly used <trace> element attributes:


requestLimit

The default number of HTTP requests stored in the application trace log is 10. If the limit is reached, ASP.NET automatically disables tracing. You can increase the number of HTTP requests using the requestLimit attribute:

 <trace enabled="true" requestLimit="40" /> 

Once the limit it reached, no other HTTP requests will be logged until the application is restarted, you hit the "clear current trace" link on the trace.axd page (see the upper-right corner of Figure 10-2), or the query string clear=1 is passed to trace.axd , like so:

http://localhost/<your application name>/trace.axd?clear=1


pageOutput

If, in addition to viewing the trace.axd file, you also want to see trace information displayed at the bottom of the page that it is associated with, add pageOutput="true " to the <trace> element:

 <trace enabled="true" pageOutput="true" /> 

The trace information you will see is identical to what would appear had you placed Trace="true " in the @ Page directive for the page (see Introduction for details).


localOnly

To show trace information to the local user (i.e., the browser making the request is on the machine serving the request) but not to remote users, make sure the <trace> element includes localOnly="true ":

 <trace enabled="true" pageOutput="true" localOnly="true" /> 

If you are viewing the trace log in the trace viewer and you want to see specific information about a request, like the kind you would see in Figure 10-1, click the "View Details" link to the right.

When deploying your application to a production environment, you can explicitly disable trace.axd by placing <httpHandler> elements like these in web.config :

 <configuration>    <system.web>       <httpHandlers>  <remove verb="*" path="trace.axd" />  </httpHandlers>    </system.web> </configuration> 



ASP. NET Cookbook
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2006
Pages: 179

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net