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.

C#
public SourceSwitch(string name);

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.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

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.

C#
public SourceSwitch(string displayName, string defaultSwitchValue);

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.

C#
#if(!ConfigFile)
                SourceSwitch sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose");
#endif

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.

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

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1