See Also: SourceSwitch Members
The TraceSource.Switch property of the System.Diagnostics.TraceSource class is a System.Diagnostics.SourceSwitch object. The System.Diagnostics.SourceSwitch class provides a SourceSwitch.Level property to test the event level of the switch. The SourceSwitch.Level property gets or sets the switch's System.Diagnostics.TraceLevel value.
You can set the event level of a System.Diagnostics.SourceSwitch through the application configuration file and then use the configured System.Diagnostics.SourceSwitch level in your application. Alternatively, you can create a System.Diagnostics.SourceSwitch in your code and set the level directly, to instrument a specific section of code.
To configure a System.Diagnostics.SourceSwitch, edit the configuration file that corresponds to the name of your application. Within this file, you can set a switch's value or clear all the switches previously set by the application. The configuration file should be formatted as shown in the following example.
<switches> <add name="SourceSwitch" value="Verbose"></add> </switches>
The switch is used to check whether a trace should be propagated or ignored. Each System.Diagnostics.TraceSource trace method calls the SourceSwitch.ShouldTrace(TraceEventType) method before calling the listeners. If the SourceSwitch.ShouldTrace(TraceEventType) method returns false, the trace is ignored and the trace method exits. If the SourceSwitch.ShouldTrace(TraceEventType) method returns true, the trace is passed to the listeners.