How to Capture ASP.NET Page Trace Events in IIS 7.0 Tracing

Introduction

In ASP.Net today, developers can add trace events to ASPX pages using Trace.Write() & Trace.Warn() calls in the script sections of their page. Typically, you use these traces to debug an application that does not work as expected.

These events appear when you enable tracing for the page (set <%@ Page Trace="True" %>). You can only view these events by default when browsing the application from the server (i.e. Localhost), or when you enable Application Tracing to keep the last given number of sessions.

However, the problems with this process are:

These traces are not persisted, so if the process goes away, so do your traces

These traces are collected regardless of the status code for the request – i.e. if it succeeds or fails, you get traces

These traces are viewed completely separately from any other infrastructure traces provided by IIS 7.0 and above or ASP.net

In IIS 7.0 and above, you can collect these traces in Failed Request Tracing or ETW tracing in addition to viewing them normally. And, you can view these traces in conjunction with IIS and ASP.net infrastructure traces.

Generating the failure condition and viewing the resulting trace capture, finding the Trace.Write and Trace.Warn calls

Prerequisites

The following steps include the prerequisites necessary for completing the tasks in this article.

Step 1 : Installing IIS 7.0 or Above

IIS 7.0 or above must first be installed. To check if IIS is installed, browse to http://localhost. If you see the "under construction" page, then IIS is installed. If IIS is not installed, refer to the "Installing IIS 7.0 and Above" guide for installation instructions.

Step 2 : Log In as Administrator

Make sure to login to the administrator account or in the Administrators group.

Note: Being in the Administrators group does not grant you complete administrator privileges by default. You must run many applications as Administrator. Right-click the application icon and choose "Run as Administrator".

Step 3 : Make a Backup

You must make a backup of the configuration before executing tasks in this article. Run the following:

Adding a New Trace.Write() & Trace.Warn() call to a Sample ASPX Page

For this scenario, we must use the ASP.Net provider's Page area, with Trace.Write calls corresponding to the Verbose verbosity level, and Trace.Warn() calls corresponding to the Warning verbosity level. Setting the verbosity level to Verbose gets both.

Step 1 : Enabling Failed Request Tracing for Your Site

Failure Request Tracing first must be enabled for the site. Steps to enable are found in the HOWTO-FailureRequestTracing Walk Through, Task 1.

We generated the traced request, so open an Administrator-elevated Internet Explorer window, enter CTRL-O to open a file, and navigate to inetpub\logs\FailedReqLogFiles\W3SVC1 folder. In the HTML Files dropdown list, select All Files.

Select the most recent FR######.xml file. You see the following:

The events display above in the trace log. Notice that the event "Doh, a warning"'s SubType Name is "AspNetPageTraceWarnEvent" - that is the Trace.Warn() event.

All Trace.Write() calls are very high verbosity (verbosity = "Verbose"); hence, the reason for the <Level>5</Level>, while all Trace.Warn() calls are logged as Warnings.

Note: There are many other "AspNetPageTraceWriteEvent" events logged. This is because all the other entries in the trace table, like Begin PreInit, etc., are all logged through the same infrastructure as well.

Summary

We finished adding trace messages to the ASPX page. We configured IIS to capture those traces, when enabled, in the Failed Request Trace Logfile. Remember that these trace entries are only logged to the trace logs if the page's trace="true" directive is set, and the ASP.NET provider with the "Page" area is defined when tracing (either using ETW or Failed Request Tracing).

By IIS Team

The IIS team is a close-knit group of passionate individuals who are enthusiastic about web technology. Our diverse team represents all corners of the globe with members from Canada, China, Germany, India, Ireland, Korea, Mexico, Russia, Vietnam, and all over the United States.