posts - 234, comments - 480, trackbacks - 56

My Links

News




I am born in Bangladesh and currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and CEO at Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh.

I also created SmartCodeGenerator

Some of my articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

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.

Print | posted on Tuesday, November 21, 2006 5:22 AM |

Feedback

Gravatar

# Doesn't work if there is an exception

Hooking up the TraceFinished event works fine as long as the page doesn't have any issues. If there is an exception thrown on the page, the TraceFinished event does not get called. This really makes it difficult to read the trace for failed pages and log them to a log source.
11/21/2008 8:44 AM | Shan McArthur
Gravatar

# re: Programmatically accessing Tracing info in Asp.Net 2.0

I have a .net application that is designed to capture trace output by using the Trace.TraceFinished event. The problem that I am running into is that when an unhandled exception occurres, I am unable to capture the Trace that lead up to the exception because the TraceFinished event is never called.Is there any way to handle it?
5/26/2009 7:20 AM | Gaurav Tyagi
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: