SourceSwitch SourceSwitch SourceSwitch SourceSwitch Class


提供多级开关,用于控制跟踪和调试输出,而无需重新编译代码。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


TraceSource类的SourceSwitch属性是一个对象。 SwitchThe Switch property of the TraceSource class is a SourceSwitch object. 类提供了一个Level属性来测试交换机的事件级别。 SourceSwitchThe SourceSwitch class provides a Level property to test the event level of the switch. 属性获取或设置开关的TraceLevel值。 LevelThe Level property gets or sets the switch's TraceLevel value.

您可以通过应用程序配置文件设置SourceSwitch的事件级别, 然后在您的应用程序SourceSwitch中使用配置的级别。You can set the event level of a SourceSwitch through the application configuration file and then use the configured SourceSwitch level in your application. 或者, 您可以SourceSwitch在代码中创建并直接设置级别, 以检测代码的特定部分。Alternatively, you can create a SourceSwitch in your code and set the level directly, to instrument a specific section of code.

若要配置SourceSwitch, 请编辑与应用程序名称对应的配置文件。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. TraceSource个跟踪方法在ShouldTrace调用侦听器之前都调用方法。Each TraceSource trace method calls the ShouldTrace method before calling the listeners. 如果该ShouldTrace方法返回false, 则将忽略该跟踪并退出跟踪方法。If the ShouldTrace method returns false, the trace is ignored and the trace method exits. 如果该ShouldTrace方法返回true, 则跟踪会传递到侦听器。If the ShouldTrace method returns true, the trace is passed to the listeners.


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

初始化 SourceSwitch 类的新实例,并且指定源的名称。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)

初始化 SourceSwitch 类的新实例,并且指定源开关的显示名称和默认值。Initializes a new instance of the SourceSwitch class, specifying the display name and the default value for the source switch.


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)


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()

获取当前实例的 TypeGets the Type of the current instance.

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

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

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

SwitchSetting 属性更改时调用。Invoked when the SwitchSetting property is changed.

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

Value 属性的值发生更改时调用。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)