<switches> 元素<switches> Element

包含跟踪开关和对该跟踪开关设置的级别。Contains trace switches and the level where the trace switches are set.

<configuration>
  <system.diagnostics>
    <switches>

语法Syntax

      <switches>
</switches>  

特性和元素Attributes and Elements

下列各节描述了特性、子元素和父元素。The following sections describe attributes, child elements, and parent elements.

特性Attributes

无。None.

子元素Child Elements

元素Element 描述Description
<add> 指定对跟踪开关设置的级别。Specifies the level where a trace switch is set.

父元素Parent Elements

元素Element 描述Description
configuration 公共语言运行时和 .NET Framework 应用程序所使用的每个配置文件中的根元素。The root element in every configuration file used by the common language runtime and .NET Framework applications.
System.diagnostics 指定用于收集、存储和路由消息的跟踪侦听器以及对跟踪开关设置的级别。Specifies trace listeners that collect, store, and route messages and the level where a trace switch is set.

备注Remarks

可以通过将跟踪开关置于配置文件中来更改其级别。You can change the level of a trace switch by putting it in a configuration file. 如果开关是 BooleanSwitch ,则可以将其打开或关闭。If the switch is a BooleanSwitch, you can turn it on and off. 如果开关是 TraceSwitch ,则可以为其分配不同的级别,以指定应用程序输出的跟踪或调试消息的类型。If the switch is a TraceSwitch, you can assign different levels to it to specify the types of trace or debug messages the application outputs.

示例Example

下面的示例演示如何使用 <switch> 元素将 General 跟踪开关设置为 TraceLevel 级别,并启用 Data 布尔型跟踪开关。The following example shows how to use the <switch> element to set the General trace switch to the TraceLevel level, and enable the Data Boolean trace switch.

<configuration>  
   <system.diagnostics>  
      <switches>  
         <add name="General" value="4" />  
         <add name="Data" value="1" />  
      </switches>  
   </system.diagnostics>  
</configuration>  

请参阅See also