Appendix B. Tracing and Debugging in .NET

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Part 6.  .NET Applications


Complicated applications cannot be put under the debugger to find out what went wrong. Duplicating or even understanding what conditions are needed to replicate the problem is often difficult. The System.Diagnostics namespace has several classes that help you instrument your application. [1]

[1] The security of your Web site or Web service is enhanced by using tracing and debugging output. You do not want to give out information in an error message that could be used to compromise your system. Capturing that information in a trace or debug log allows the program to generate a generic error message for the user. You could also assign an identifier to the user message that is also recorded with the log message. If necessary, that id could be used to help the user diagnose any problems with his or her system.

Instrumenting your application for debugging and tracing will enable you to make your applications more robust. It also illustrates the common pattern of how the framework divides classes into separate tasks (writing the output, controlling the output, and the output destination) so that you can customize parts and still rely on the .NET Framework classes for the rest. The mechanics of instrumenting your application has three aspects.

The Trace and Debug classes are used to generate the debug or trace output. These classes have identical methods and properties that allow you to write diagnostic output. They do not, however, specify the destination of the output.

The Listeners classes are used to direct the output to various destinations, although a default destination does exist.

Finally, there are mechanisms for turning on or off the instrumentation. You can set the DEBUG and TRACE compilation flags to have different tracing for debug or release builds. You can have the output of the Trace and Debug classes depend on the conditional evaluation of expressions. Or, you can control the verbosity of the output, depending on your need for information, using the BooleanSwitch and TraceSwitch classes.


Team-Fly    
Top
 


Application Development Using Visual BasicR and .NET
Application Development Using Visual BasicR and .NET
ISBN: N/A
EAN: N/A
Year: 2002
Pages: 190

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net