Welcome to Bangladesh Microsoft Technology Community Sign in | Join | Help

Programmatically accessing Tracing info in Asp.Net 2.0

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

<configuration>
<system.web>
<trace enabled="true" writeToDiagnosticsTrace="true" />
</system.web>
</configuration>

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 + "<BR>");
        Response.Write (traceContextRecord.Message + "<BR>");
        //..... 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.

Published Tuesday, November 21, 2006 2:21 AM by Shahed

Comments

No Comments

Anonymous comments are disabled