Redigera

Dela via


SourceSwitch Constructors

Definition

Initializes a new instance of the SourceSwitch class.

Overloads

SourceSwitch(String)

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

SourceSwitch(String, String)

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

SourceSwitch(String)

Source:
SourceSwitch.cs
Source:
SourceSwitch.cs
Source:
SourceSwitch.cs

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

public:
 SourceSwitch(System::String ^ name);
public SourceSwitch (string name);
new System.Diagnostics.SourceSwitch : string -> System.Diagnostics.SourceSwitch
Public Sub New (name As String)

Parameters

name
String

The name of the source.

Remarks

The name parameter is used to set the value of the DisplayName property.

To set the level of your SourceSwitch in a .NET Framework app, edit the configuration file that corresponds to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. To add a source switch, the configuration file should be formatted as shown in the following example.

<configuration>  
  <system.diagnostics>  
    <switches>  
      <add name="SourceSwitch" value="Verbose" ></add>  
    </switches>  
  </system.diagnostics>  
</configuration>  

Applies to

SourceSwitch(String, String)

Source:
SourceSwitch.cs
Source:
SourceSwitch.cs
Source:
SourceSwitch.cs

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

public:
 SourceSwitch(System::String ^ displayName, System::String ^ defaultSwitchValue);
public SourceSwitch (string displayName, string defaultSwitchValue);
new System.Diagnostics.SourceSwitch : string * string -> System.Diagnostics.SourceSwitch
Public Sub New (displayName As String, defaultSwitchValue As String)

Parameters

displayName
String

The name of the source switch.

defaultSwitchValue
String

The default value for the switch.

Examples

The following code example creates a SourceSwitch with the name "SourceSwitch" and a default value of Verbose. This code example is part of a larger example provided for the TraceSource class.

#if(!ConfigFile)
                SourceSwitch sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose");
#endif
#If (ConfigFile = False) Then
            Dim sourceSwitch As New SourceSwitch("SourceSwitch", "Verbose")
#End If

Remarks

The displayName parameter is used to set the value of the DisplayName property; the defaultSwitchValue parameter is saved as a field and used to initialize the Value property on first reference.

Note

For .NET Framework apps, if the switch is defined in a configuration file and the value attribute is specified, the configuration file value takes precedence and the defaultSwitchValue is ignored.

To set the level of your SourceSwitch in a .NET Framework app, edit the configuration file that corresponds to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all the switches previously set by the application. To add a source switch, the configuration file should be formatted as shown in the following example.

<configuration>  
  <system.diagnostics>  
    <switches>  
      <add name="SourceSwitch" value="Verbose" ></add>  
    </switches>  
  </system.diagnostics>  
</configuration>  

Applies to