10.2. Uncovering Problems Application Wide

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.

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.

Application-level tracing output (trace.axd)

Figure 10-2. Application-level tracing output (trace.axd)

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 ...

Get ASP.NET Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.