Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the SourceSwitch class.
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. |
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)
The name of the source.
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>
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 |
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)
The name of the source switch.
The default value for the switch.
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
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>
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 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in