Chapter 13. Tracing and Debugging in .NET

for RuBoard

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 their 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 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.

for RuBoard


Application Development Using C# and .NET
Application Development Using C# and .NET
ISBN: 013093383X
EAN: 2147483647
Year: 2001
Pages: 158

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