Provides a multilevel switch to control tracing and debug output without recompiling your code.
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 = class inherit [%$TOPIC/4h0a215t_en-us_VS_110_2_0_3_0_0%] end
Thetype exposes the following members.
|Attributes||Gets the custom switch attributes defined in the application configuration file. (Inherited from Switch.)|
|Description||Gets a description of the switch. (Inherited from Switch.)|
|DisplayName||Gets a name used to identify the switch. (Inherited from Switch.)|
|Level||Gets or sets the level of the switch.|
|SwitchSetting||Gets or sets the current setting for this switch. (Inherited from Switch.)|
|Value||Gets or sets the value of the switch. (Inherited from Switch.)|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetSupportedAttributes||Gets the custom attributes supported by the switch. (Inherited from Switch.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|OnSwitchSettingChanged||Invoked when the SwitchSetting property is changed. (Inherited from Switch.)|
|OnValueChanged||Invoked when the value of the Value property changes. (Overrides SwitchOnValueChanged.)|
|ShouldTrace||Determines if trace listeners should be called, based on the trace event type.|
|ToString||Returns a string that represents the current object. (Inherited from Object.)|
You can set the event level of a through the application configuration file and then use the configured level in your application. Alternatively, you can create a in your code and set the level directly, to instrument a specific section of code.
To configure a , 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 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.
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.