How to: Enable Tracing for an ASP.NET Application
Instead of enabling tracing for individual pages, you can enable it for your entire application. In that case, every page in your application displays trace information. Application tracing is useful when you are developing an application because you can easily enable it and disable it without editing individual pages. When your application is complete, you can turn off tracing for all pages at once.
When you enable tracing for an application, ASP.NET collects trace information for each request to the application, up to the maximum number of requests you specify. The default number of requests is 10. You can view trace information with the trace viewer.
By default, when the trace viewer reaches its request limit, the application stops storing trace requests. However, you can configure application-level tracing to always store the most recent tracing data, discarding the oldest data when the maximum number of requests is reached. For more information, see Application-Level ASP.NET Tracing Overview.
To disable tracing for an individual page in the application, set the Trace attribute in that page's @ Page directive to false. Any Write or Warn statements that you include in a page's code are stored and returned to the trace viewer only.
To enable tracing for an application
Open your Web site's Web.config file. If no Web.config file exists, create a new file in the root folder and copy the following into it:
<?xml version="1.0"?> <configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"> <system.web> </system.web> </configuration>
Add a trace element as a child of the system.web element.
In the trace element, set the enabled attribute to true.
If you want trace information to appear at the end of the page that it is associated with, set the trace element's pageOutput attribute to true. If you want tracing information to be displayed only in the trace viewer, set the pageOutput attribute to false.
For example, the following application trace configuration collects trace information for up to 40 requests and allows browsers on computers other than the server of origin to display the trace viewer. Trace information is not displayed in individual pages.
<configuration> <system.web> <trace enabled="true" pageOutput="false" requestLimit="40" localOnly="false"/> </system.web> </configuration>
The ASP.NET configuration system is case-sensitive.