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