SourceSwitch Class
 

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

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

Inheritance Hierarchy
SystemObject
   System.DiagnosticsSwitch
    System.DiagnosticsSourceSwitch

Syntax
public class SourceSwitch : Switch
public ref class SourceSwitch : Switch
type SourceSwitch = 
    class
        inherit Switch
    end
Public Class SourceSwitch
	Inherits Switch
Constructors
NameDescription
System_CAPS_pubmethod SourceSwitch

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

System_CAPS_pubmethod SourceSwitch

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

Properties
NameDescription
System_CAPS_pubproperty

Gets the custom switch attributes defined in the application configuration file.(Inherited from Switch.)

System_CAPS_pubproperty

Gets a description of the switch.(Inherited from Switch.)

System_CAPS_pubproperty

Gets a name used to identify the switch.(Inherited from Switch.)

System_CAPS_pubproperty

Gets or sets the level of the switch.

System_CAPS_protproperty

Gets or sets the current setting for this switch.(Inherited from Switch.)

System_CAPS_protproperty

Gets or sets the value of the switch.(Inherited from Switch.)

Methods
NameDescription
System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethod Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_protmethod GetSupportedAttributes

Gets the custom attributes supported by the switch.(Inherited from Switch.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethod OnSwitchSettingChanged

Invoked when the property is changed.(Inherited from Switch.)

System_CAPS_protmethod OnValueChanged

Invoked when the value of the property changes.(Overrides SwitchOnValueChanged.)

System_CAPS_pubmethod ShouldTrace

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

System_CAPS_pubmethod ToString

Returns a string that represents the current object.(Inherited from Object.)

Remarks

The property of the TraceSource class is a SourceSwitch object. The SourceSwitch class provides a property to test the event level of the switch. The 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.

Version Information
Universal Windows Platform
Available since 10
.NET Framework
Available since 2.0
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.

Return to top