Using Switches to Enable Diagnostics

Team-Fly    

 
Application Development Using Visual Basic and .NET
By Robert J. Oberg, Peter Thorsteinson, Dana L. Wyatt
Table of Contents
Appendix B.  Tracing and Debugging in .NET


Switches give you finer grain control over the diagnostic output. You can use the BooleanSwitch class to turn output on or off based on the value of its Enabled property.

The TraceSwitch class gives you five hierarchical levels of control for its Level property: TraceError , TraceWarning , TraceInfo , TraceVerbose , and Off . These values are part of the TraceLevelEnumeration . Setting a lower Trace level means that the higher ones are set as well. For example, if the TraceWarning level is set, both the TraceError and TraceWarning levels are enabled.

 DebugBooleanSwitch.Enabled = True Debug.WriteLineIf(DebugBooleanSwitch.Enabled, _    "Debug Boolean Switch enabled!") ...   Trace.WriteLineIf(TraceLevelSwitch.TraceError, _    "TraceError!") 

The constructors for these switches take two parameters. The first is the name of the switch, the second is a text description of the switch. Both BooleanSwitch and TraceSwitch classes inherit from the abstract class Switch . You can write your own customized switch classes by inheriting from the Switch class. Note that the Enabled property of the BooleanSwitch and the Level and named level properties of the TraceSwitch are not part of the Switch class.


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