<switches> 的 <add> 元素<add> Element for <switches>

指定对跟踪开关设置的级别。Specifies the level where a trace switch is set.



<add name="switch name"  

特性和元素Attributes and Elements

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


属性Attribute 描述Description
namename 必需的特性。Required attribute.

指定开关的名称。Specifies the name of the switch. 此属性的值对应于传递给 switch 构造函数的 displayName 参数。The value of this attribute corresponds to the displayName parameter that is passed to switch constructor.
valuevalue 必需的特性。Required attribute.

指定开关的级别。Specifies the level of the switch.

子元素Child Elements


父元素Parent Elements

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


可以通过将跟踪开关置于配置文件中来更改其级别。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.


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

         <add name="General" value="4" />  
         <add name="Data" value="1" />  

请参阅See also