Monday, December 10, 2007

Page level Tracing::::::::::::::::::



ASP.NET tracing can be enabled on a page-by-page basis by adding "_Trace=_true" to the Page directive in any ASP.NET page:



<_%_@ _language="_" _trace="_" _tracemode_ =" _" _inherits =" _" _codefile="_">



Additionally, you can add the TraceMode attribute that sets SortByCategory or the default,
SortByTime. You can use SortByTime to see the methods that take up the most CPU time for your application. You can enable tracing programmatically using the Trace.IsEnabled property.




Application Tracing::::::::::::::::::::::You can enable tracing for the entire application by adding tracing settings in web.config. In below example, _pageOutput=_"_false" and requestLimit=_"_20" are used, so trace information is stored for 20 requests, but not displayed on the page because pageOutput attribute is set to false.



<_configuration>

<_appsettings/>

<_connectionstrings/>

<_system._web>

<_compilation _debug="_">

<_authentication _mode="_">

<_trace _enabled ="_" _pageoutput ="_" _requestlimit ="_" _tracemode ="_">
<_/_system._web>

<_/_configuration>

The page-level settings take precedence over settings in Web.config, so if enabled=_"_false" is set in Web.config but trace=_"_true" is set on the page, tracing occurs.

Viewing Trace Data::::::::::::
Tracing can be viewed for multiple page requests at the application level by requesting a special page called trace.axd. When ASP.NET detects an HTTP request for trace.axd, that request is handled by the TraceHandler rather than by a page.

Create a website and a page, and in the Page_Load event, call Trace.Write(). Enable tracing in Web.config as shown below.

<_system.web>
<_compilation _debug="_">
<_authentication _mode="_">
<_trace _enabled ="_" _pageoutput ="_">


_protected _void _Page_Load_(_object _sender, _EventArgs _e)
{
_System.Diagnostics.Trace.Write_(_"This is Page_Load method!"_);
}


Trace.axd::::::::::: Page output of tracing shows only the data collected for the current page
request. However, if you want to collect detailed information for all the requests then we need to use Trace.axd. We can invoke Trace.axd tool for the application using the following URL
http://localhost/application-name/trace.axd. Simply replace page name in URL with Trace.axd. That is, in our case. We should use following URL (Address bar) for our application as shown below.

No comments: