spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / asp / debugging To page 1To page 2To page 3current page
[previous]

Debugging and Tracing in ASP.NET

Web Designers with Mad Skills!
Aquent
US-CA-Los Angeles

Justtechjobs.com Post A Job | Post A Resume
Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

Tracing

The most important class for tracing is System.Diagostics.Trace. The Trace class has the same methods and properties as the Debug class except that its methods have the Conditional attribute of TRACE. In Visual Studio .NET TRACE is defined in both debug and release builds by default. So the methods of the Trace class are always executed by default. So this class should be used only when we always want the output.

As with Debug, trace output goes to all listeners that are registered with the Trace class. The same listeners that are used for Debug can be used for Trace.

The only other difference is that while Debug has a binary nature of either being on or off, Trace should be used in a multilevel hierarchy. To do this a switch called TraceSwitch is defined. This is similar to the BooleanSwitch class except that it has a level property that can have five values defined in the TraceLevel enumeration. Combined with the TraceSwitch class Trace can be used to provide flexible tracing of applications as shown below.

// Create a TraceSwitch.
static TraceSwitch traceSwitch = new TraceSwitch("trace", "Application");
 
static public void TraceOutput() 
{
	//  Verbose Tracing.
	if(traceSwitch.TraceVerbose)
	{
		Trace.Write("Trace Output - Verbose");
	}
 
	// Error Tracing
	if(traceSwitch.TraceError)
	{
		Trace.WriteLine("Trace Output - Error");
	}
}

As always, though the switches, levels and listeners can be defined in code, they should be defined in the application's config file so that they can be changed whenever necessary without recompilation.

Conclusion

The System.Diagnostics namespace provides useful classes for debugging applications. These become important specifically while writing server side applications where IDE debuggers are difficult to use. These classes provide extensive debugging, tracing, event logging and performance monitoring features.

About the Author

Utpal Chakraborty is Manager, Software Engineering at Organic (http://www.organic.com). He has extensive experience in developing enterprise applications using Microsoft and non-Microsoft technologies. He can be reached at uchakraborty@organic.com.


home / programming / asp / debugging To page 1To page 2To page 3current page
[previous]

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Review: Lenovo ThinkPad SL300 · OCZ PC3-10666 Gold 2x1GB Review · Apple Recommends Antivirus for Macs

Created: December 4, 2002
Revised: December 4, 2002

URL: http://webreference.com/programming/asp/debugging/4.html