How to: Create and Initialize Trace Switches
In order to use trace switches, you must first create them and place them in your code. There are two predefined classes from which you can create switch objects: the BooleanSwitch class and the TraceSwitch class. You would use BooleanSwitch if you care only about whether or not a tracing message appears; you would use TraceSwitch if you want to discriminate between levels of tracing. If you use a TraceSwitch, you can define your own debugging messages and associate them with different trace levels. You can use both types of switches with either tracing or debugging. By default, a BooleanSwitch is disabled and a TraceSwitch is set to level TraceLevelOff. Trace switches can be created and placed in any part of your code that might use them.
Although you can set trace levels and other configuration options in code, we recommend that you use the configuration file to manage the state of your switches. This is because managing the configuration of your switches in the configuration system gives you greater flexibility — you can turn on and off various switches and change levels without recompiling your application. For more information, see Configuring Trace Switches.