SourceSwitch SourceSwitch SourceSwitch SourceSwitch Class

Definition

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

public ref class SourceSwitch : System::Diagnostics::Switch
public class SourceSwitch : System.Diagnostics.Switch
type SourceSwitch = class
    inherit Switch
Public Class SourceSwitch
Inherits Switch
Inheritance
SourceSwitchSourceSwitchSourceSwitchSourceSwitch

Remarks

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.

<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.

Constructors

SourceSwitch(String) SourceSwitch(String) SourceSwitch(String) SourceSwitch(String)

Initializes a new instance of the SourceSwitch class, specifying the name of the source.

SourceSwitch(String, String) SourceSwitch(String, String) SourceSwitch(String, String) SourceSwitch(String, String)

Initializes a new instance of the SourceSwitch class, specifying the display name and the default value for the source switch.

Properties

Attributes Attributes Attributes Attributes

Gets the custom switch attributes defined in the application configuration file.

(Inherited from Switch)
Description Description Description Description

Gets a description of the switch.

(Inherited from Switch)
DisplayName DisplayName DisplayName DisplayName

Gets a name used to identify the switch.

(Inherited from Switch)
Level Level Level Level

Gets or sets the level of the switch.

SwitchSetting SwitchSetting SwitchSetting SwitchSetting

Gets or sets the current setting for this switch.

(Inherited from Switch)
Value Value Value Value

Gets or sets the value of the switch.

(Inherited from Switch)

Methods

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes()

Gets the custom attributes supported by the switch.

(Inherited from Switch)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
OnSwitchSettingChanged() OnSwitchSettingChanged() OnSwitchSettingChanged() OnSwitchSettingChanged()

Invoked when the SwitchSetting property is changed.

(Inherited from Switch)
OnValueChanged() OnValueChanged() OnValueChanged() OnValueChanged()

Invoked when the value of the Value property changes.

ShouldTrace(TraceEventType) ShouldTrace(TraceEventType) ShouldTrace(TraceEventType) ShouldTrace(TraceEventType)

Determines if trace listeners should be called, based on the trace event type.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to