.NET Framework Class Library
SourceSwitch Class

Provides a multilevel switch to control tracing and debug output without recompiling your code.

Inheritance Hierarchy

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)
Public Class SourceSwitch _
	Inherits [%$TOPIC/4h0a215t_en-us_VS_110_2_0_0_0_0%]
public class SourceSwitch : [%$TOPIC/4h0a215t_en-us_VS_110_2_0_1_0_0%]
public ref class SourceSwitch : public [%$TOPIC/4h0a215t_en-us_VS_110_2_0_2_0_0%]
type SourceSwitch =  
        inherit [%$TOPIC/4h0a215t_en-us_VS_110_2_0_3_0_0%] 
public class SourceSwitch extends [%$TOPIC/4h0a215t_en-us_VS_110_2_0_4_0_0%]

The SourceSwitch type exposes the following members.

Public method SourceSwitch(String)Initializes a new instance of the SourceSwitch class, specifying the name of the source.
Public method SourceSwitch(String, String)Initializes a new instance of the SourceSwitch class, specifying the display name and the default value for the source switch.
Public property AttributesGets the custom switch attributes defined in the application configuration file. (Inherited from Switch.)
Public property DescriptionGets a description of the switch. (Inherited from Switch.)
Public property DisplayNameGets a name used to identify the switch. (Inherited from Switch.)
Public property LevelGets or sets the level of the switch.
Protected property SwitchSettingGets or sets the current setting for this switch. (Inherited from Switch.)
Protected property ValueGets or sets the value of the switch. (Inherited from Switch.)
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Protected method GetSupportedAttributesGets the custom attributes supported by the switch. (Inherited from Switch.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Protected method OnSwitchSettingChangedInvoked when the SwitchSetting property is changed. (Inherited from Switch.)
Protected method OnValueChangedInvoked when the value of the Value property changes. (Overrides SwitchOnValueChanged.)
Public method ShouldTraceDetermines if trace listeners should be called, based on the trace event type.
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)

The Switch property of the TraceSource class is a SourceSwitch object. The SourceSwitch class provides a Level property to test the event level of the switch. The Level property gets or sets the switch's TraceLevel value.

You can set the event level of a SourceSwitch through the application configuration file and then use the configured SourceSwitch level in your application. Alternatively, you can create a SourceSwitch in your code and set the level directly, to instrument a specific section of code.

To configure a 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.

  <add name="SourceSwitch" value="Verbose"></add>

The switch is used to check whether a trace should be propagated or ignored. Each TraceSource trace method calls the ShouldTrace method before calling the listeners. If the ShouldTrace method returns false, the trace is ignored and the trace method exits. If the ShouldTrace method returns true, the trace is passed to the listeners.

Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.