Enabling Tracing Programmatically in ASP.NET

By | January 2, 2011

ASP.NET provides a internal details of page related information by enabling Tracing. To use tracing, we need to explicitly enable it from Page directives as shown in below

image

Enable tracing from page directives is one of the easiest way to enable it. But, we can use Page.Trace object to enable or disabled the tracing programmatically.

protected void Page_Load(object sender, EventArgs e)
 { 
//check for null query string as well
if (Request.QueryString["EnableTracing"].Equals("true")) 
{
 Trace.IsEnabled = true;
 }
 }

Trace object is an Instance of TraceContextClass which is actually control all the operation related with Tracing.This is extremely useful when you want to enable or disable tracing for a page based on some condition or query string.

protected void Page_Load(object sender, EventArgs e)
 {
//check for null query string as well
 if (Request.QueryString["EnableTracing"].Equals("true") && UserRole.Role == "Admin") 
{
 Trace.IsEnabled = true;
 } 
} 

So, now you can enable or disable Tracing whenever you want.

2 thoughts on “Enabling Tracing Programmatically in ASP.NET

  1. Pingback: Tweets that mention Enabling Tracing Programmatically in ASP.NET | Daily .Net Tips -- Topsy.com

  2. Pingback: Dew Drop – January 2, 2011 | Alvin Ashcraft's Morning Dew

Comments are closed.