Using Switches to Enable Diagnostics

for RuBoard

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.

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