posts - 217, comments - 218, trackbacks - 239

My Links

News




I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net) and born in Bangladesh.
I work for Ocean Informatics Pty Ltd as a Senior Developer - Analyst.
I am also co-founder and core developer of Pageflakes (acquired by LiveUniverse) www.pageflakes.com
and most recently created SmartCodeGenerator

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

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 8 and 8 and type the answer here:

Powered by: