Enabling or Disabling Switches

for RuBoard

You can use settings in your application configuration file to enable or disable a switch at startup. This can also be done programmatically.

Configuration File Switch Settings

You can set the switch's initial setting in the application's configuration file.

 <configuration>    <system.diagnostics      <switches>        <add name="DebugSwitch" value = "0" />        <add name="TraceSwitch" value = "2" />      </switches>    </system.diagnostics>  </ configuation> 

If no values are found, the initial value of the Enabled property of the BooleanSwitch with the name DebugSwitch is set to false and the TraceSwitch's Level property is set to TraceOff .

Programmatic Switch Settings

The Enabled property of the BooleanSwitch can be set to true or false. The Level property of the TraceSwitch can be set to one of the options of the TraceLevel enumeration: TraceOff , TraceError , TraceWarning , TraceInfo , TraceVerbose . You can get the level of the TraceSwitch's setting by examining the TraceError , TraceWarning , TraceInfo , TraceVerbose properties.

Using Switches to Control Output

You can test the value of the switch before you write, debug, or trace output. You can do this with an if statement, or as an argument to one of the Trace or Debug classes' methods .

 Trace.WriteLineIf(TraceLevelSwitch.TraceError,                                             "TraceError!");  Trace.WriteLineIf(TraceLevelSwitch.TraceWarning,                                           "TraceWarning!");  Trace.WriteLineIf(TraceLevelSwitch.TraceInfo,                                            "InfoMessage!");  Trace.WriteLineIf(TraceLevelSwitch.TraceVerbose,                                         "VerboseMessage!"); 

Since you can set these values outside of your program's code, you can select the circumstances under which you get a particular level of debug or trace output. For example, you can turn on TraceVerbose output if you really need a high level of diagnostics, but turn it off after you have found the problem.

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