System.Diagnostics.Switch Class

Provides an abstract base class to create new debugging and tracing switches.

See Also: Switch Members

Syntax

public abstract class Switch

Remarks

A switch provides an efficient mechanism for controlling tracing and debugging output at run time using external settings. The System.Diagnostics.Switch class implements default behavior for switches, allowing you to change the switch level at run time.

This class is the base class for the System.Diagnostics.BooleanSwitch, System.Diagnostics.SourceSwitch and the System.Diagnostics.TraceSwitch classes. These switches meet most debugging and tracing needs. For more information about trace switches, see Trace Switches.

You must enable tracing or debugging to use a switch. The following syntax is compiler specific. If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.

To set the level of your switch, edit the configuration file that corresponds to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. The configuration file should be formatted like the following example:

Example

<configuration>
  <system.diagnostics>
    <switches>
      <add name="mySwitch" value="true" />
    </switches>
  </system.diagnostics>
</configuration>

This example configuration section defines a System.Diagnostics.BooleanSwitch with the Switch.DisplayName property set to mySwitch and the BooleanSwitch.Enabled value set to true. Within your application, you can use the configured switch value by creating a System.Diagnostics.BooleanSwitch with the same name, as shown in the following code example.

code reference: Classic Switch Example#4

Requirements

Namespace: System.Diagnostics
Assembly: System (in System.dll)
Assembly Versions: 1.0.3300.0, 1.0.5000.0, 2.0.0.0, 4.0.0.0