Thursday, July 12, 2007

Programmatically accessing Tracing info in Asp.Net 2.0

For enabling Tracing we normally Tweak the config file right....

But in asp.net 2.0 you can do a bit more...

void Page_Load (object sender, EventArgs e)
{
Trace.TraceFinished +=
new TraceContextEventHandler (TraceHasFinished);
}

void TraceHasFinished (object sender, TraceContextEventArgs e)
{
foreach (TraceContextRecord traceContextRecord in e.TraceRecords)
{
Response.Write (traceContextRecord.Category + "
");
Response.Write (traceContextRecord.Message + "
");
//..... Do your bits .......
//...Write as XML....
//....Or Write to Database....Up to you....
}
}

How cool is that! you have now programmatic access. Just register to the event TraceFinished of the TraceContext class and loop through the e.TraceRecords.

No comments:

Post a Comment