Saturday, July 21, 2007

Tracing

Tracing is a technique for recording events
Tu enable tracing at different levels, do as under:
Application level: Application’s web.config, set Enabled to true
Page level: @Page directive, Trace attribute to True in web form’s html
Write trace to a file: web.config PageOutput=”False”, trace is written to Trace.axd in application’s root folder

Customizing Tracing:
element include a RequestLimit attribute to specify how many page requests to write to trace file
Writing messages to trace log using Write and Warn method

Code Listing: Tracing
Code Listing: Trace

using System.Diagnostics;

private void Page_Error(object sender, System.EventArgs e )
{
if(Trace.IsEnabled)
{
string strMessage;
if(Request.Browser.AOL)
strMessage = “AOL Browser”;
else
strMessage = ”Non AOL Browser”;

Trace.Warn(“Error”, strMessage, Server.GetLastError());
}

Server.ClearError();
Response.Redirect(“Trace.aspx”);


}

No comments:

Post a Comment