|
50 | 50 | ## Remarks
|
51 | 51 | You can use a Boolean trace switch to enable or disable messages based on their importance. Use the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property to get the current value of the switch.
|
52 | 52 |
|
53 |
| - You can enable or disable a <xref:System.Diagnostics.BooleanSwitch> through the application configuration file and then use the configured <xref:System.Diagnostics.BooleanSwitch> value in your application. Alternately, you can create a <xref:System.Diagnostics.BooleanSwitch> in your code and set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property directly to instrument a specific section of code. |
54 |
| - |
55 |
| - To configure a <xref:System.Diagnostics.BooleanSwitch>, edit the configuration file that corresponds to the name of your application. Within this file, you can add or remove a switch, set a switch's value, or clear all the switches previously set by the application. The configuration file should be formatted like the following example. |
| 53 | +You can create a <xref:System.Diagnostics.BooleanSwitch> in your code and set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property directly to instrument a specific section of code. |
| 54 | +
|
| 55 | +For .NET Framework apps only, you can also enable or disable a <xref:System.Diagnostics.BooleanSwitch> through the application configuration file and then use the configured <xref:System.Diagnostics.BooleanSwitch> value in your application. To configure a <xref:System.Diagnostics.BooleanSwitch>, edit the configuration file that corresponds to the name of your application. Within this file, you can add or remove a switch, set a switch's value, or clear all the switches previously set by the application. The configuration file should be formatted like the following example. |
56 | 56 |
|
57 | 57 | ```xml
|
58 | 58 | <configuration>
|
|
64 | 64 | </configuration>
|
65 | 65 | ```
|
66 | 66 |
|
67 |
| - This example configuration section defines a <xref:System.Diagnostics.BooleanSwitch> with the <xref:System.Diagnostics.Switch.DisplayName%2A> property set to `mySwitch` and the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> value set to `true`. Within your application, you can use the configured switch value by creating a <xref:System.Diagnostics.BooleanSwitch> with the same name, as shown in the following code example. |
| 67 | + This example configuration section defines a <xref:System.Diagnostics.BooleanSwitch> with the <xref:System.Diagnostics.Switch.DisplayName%2A> property set to `mySwitch` and the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> value set to `true`. Within your .NET Framework application, you can use the configured switch value by creating a <xref:System.Diagnostics.BooleanSwitch> with the same name, as shown in the following code example. |
68 | 68 |
|
69 | 69 | :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic BooleanSwitch.BooleanSwitch Example/CPP/remarks.cpp" id="Snippet2":::
|
70 | 70 | :::code language="csharp" source="~/snippets/csharp/System.Diagnostics/BooleanSwitch/Overview/remarks.cs" id="Snippet2":::
|
71 | 71 | :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic BooleanSwitch.BooleanSwitch Example/VB/remarks.vb" id="Snippet2":::
|
72 |
| - |
73 |
| - By default, the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property is set using the value specified in the configuration file. Configure the switch with a value of 0 to set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property to `false`; configure the switch with a nonzero value to set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property to `true`. If the <xref:System.Diagnostics.BooleanSwitch> constructor cannot find initial switch settings in the configuration file, the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property of the new switch is set to `false` by default. |
| 72 | +
|
| 73 | +For .NET Core and .NET 5+ apps, the <xref:System.Diagnostics.BooleanSwitch.Enabled> property of the new switch is set to `false` by default. |
| 74 | +
|
| 75 | +For .NET Framework apps, the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property is set using the value specified in the configuration file. Configure the switch with a value of 0 to set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property to `false`; configure the switch with a nonzero value to set the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property to `true`. If the <xref:System.Diagnostics.BooleanSwitch> constructor cannot find initial switch settings in the configuration file, the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property of the new switch is set to `false`. |
74 | 76 |
|
75 | 77 | You must enable tracing or debugging to use a switch. The following syntax is compiler specific. If you use compilers other than C# or Visual Basic, refer to the documentation for your compiler.
|
76 | 78 |
|
|
84 | 86 | For more information on instrumenting your application, see <xref:System.Diagnostics.Debug> and <xref:System.Diagnostics.Trace>. For more information about configuring and using trace switches, see [Trace Switches](/dotnet/framework/debug-trace-profile/trace-switches).
|
85 | 87 |
|
86 | 88 | > [!NOTE]
|
87 |
| -> To improve performance, you can make <xref:System.Diagnostics.BooleanSwitch> members `static` in your class. |
88 |
| - |
89 |
| - |
| 89 | +> To improve performance, you can make <xref:System.Diagnostics.BooleanSwitch> members `static` in your class. |
90 | 90 |
|
91 | 91 | ## Examples
|
92 | 92 | The following example creates a <xref:System.Diagnostics.BooleanSwitch> and uses the switch to determine whether to print an error message. You create the switch at the class level. The `Main` method passes its location to `MyMethod`, which prints an error message and where the error occurred.
|
|
162 | 162 | <format type="text/markdown"><![CDATA[
|
163 | 163 |
|
164 | 164 | ## Remarks
|
165 |
| - When you create a <xref:System.Diagnostics.BooleanSwitch>, the `displayName` parameter is used to find initial switch settings. If the constructor cannot find initial settings, the <xref:System.Diagnostics.BooleanSwitch.Enabled%2A> property is set to `false` (disabled). |
| 165 | + When you create a <xref:System.Diagnostics.BooleanSwitch>, the `displayName` parameter is used to find the initial switch settings for .NET Framework apps in the application configuration file. If the constructor cannot find initial settings, or for .NET Core and .NET 5+ apps, the <xref:System.Diagnostics.BooleanSwitch.Enabled> property is set to `false` (disabled). |
166 | 166 |
|
167 |
| - To set the level of your <xref:System.Diagnostics.BooleanSwitch>, edit the configuration file corresponding to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all switches previously set by the application. The configuration file should be formatted like the following example: |
| 167 | + To set the level of your <xref:System.Diagnostics.BooleanSwitch> in a .NET Framework app, edit the configuration file corresponding to the name of your application. Within this file, you can add a switch and set its value, remove a switch, or clear all switches previously set by the application. The configuration file should be formatted like the following example: |
168 | 168 |
|
169 | 169 | ```xml
|
170 | 170 | <configuration>
|
|
180 | 180 | ```
|
181 | 181 |
|
182 | 182 | > [!NOTE]
|
183 |
| -> The switches you created should be `static`. |
184 |
| - |
185 |
| - |
| 183 | +> The switches you created should be `static`. |
186 | 184 |
|
187 | 185 | ## Examples
|
188 | 186 | The following example creates a <xref:System.Diagnostics.BooleanSwitch> and uses the switch to determine whether to print an error message. The switch is created at the class level. The `Main` method passes its location to `MyMethod`, which prints an error message and where the error occurred.
|
|
245 | 243 | <param name="description">The description of the switch.</param>
|
246 | 244 | <param name="defaultSwitchValue">The default value of the switch.</param>
|
247 | 245 | <summary>Initializes a new instance of the <see cref="T:System.Diagnostics.BooleanSwitch" /> class with the specified display name, description, and default switch value.</summary>
|
248 |
| - <remarks> |
249 |
| - <format type="text/markdown"><![CDATA[ |
250 |
| - |
251 |
| -## Remarks |
252 |
| - The `displayName` parameter is used to set the value of the <xref:System.Diagnostics.Switch.DisplayName%2A> property, and the `description` parameter is use to set the value of the <xref:System.Diagnostics.Switch.Description%2A> property. The `defaultSwitchValue` parameter is saved as a field and used to initialize the <xref:System.Diagnostics.Switch.Value%2A> property on first reference. For more information about constructor use, see the <xref:System.Diagnostics.BooleanSwitch.%23ctor%28System.String%2CSystem.String%29> constructor. |
253 |
| - |
254 |
| - ]]></format> |
255 |
| - </remarks> |
| 246 | + <remarks>To be added.</remarks> |
256 | 247 | </Docs>
|
257 | 248 | </Member>
|
258 | 249 | <Member MemberName="Enabled">
|
|
0 commit comments