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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.