<system.diagnostics> 元素<system.diagnostics> Element

指定用于收集、存储和路由消息的跟踪侦听器以及对跟踪开关设置的级别。Specifies trace listeners that collect, store, and route messages and the level where a trace switch is set.




特性和元素Attributes and Elements

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



子元素Child Elements

元素Element 描述Description
<assert> 指定调用 Debug.Assert 方法时是否显示消息框;另外指定要写入消息的文件的名称。Specifies whether to display a message box when you call the Debug.Assert method; also specifies the name of the file to write messages to.
<performanceCounters> 指定由性能计数器共享的全局内存的大小。Specifies the size of the global memory shared by performance counters.
<sharedListeners> 包含任何源或跟踪元素可以引用的侦听器。Contains listeners that any source or trace element can reference. 可以按名称将标识为共享侦听器的侦听器添加到源或跟踪。Listeners identified as shared listeners can be added to sources or traces by name.
<sources> 指定启动跟踪消息的跟踪源。Specifies trace sources that initiate tracing messages.
<switches> 包含跟踪开关和设置跟踪开关的级别。Contains trace switches and the levels where the trace switches are set.
<trace> 包含用于收集、存储和路由跟踪消息的侦听器。Contains listeners that collect, store, and route tracing messages.

父元素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>The following example shows how to embed a trace switch and a trace listener inside the <system.diagnostics> element. General跟踪开关设置为 TraceLevel 级别。The General trace switch is set to the TraceLevel level. 跟踪侦听器会 myListener 创建一个名为的文件 MyListener.log ,并将输出写入文件。The trace listener myListener creates a file called MyListener.log and writes the output to the file.


在 .NET Framework 2.0 版中,你可以使用文本指定开关值。In the .NET Framework version 2.0, you can use text to specify the value for a switch. 例如,你可以为指定, true BooleanSwitch 也可以使用表示枚举值的文本(例如) Error TraceSwitchFor example, you can specify true for a BooleanSwitch or use the text representing an enumeration value such as Error for a TraceSwitch. <add name="myTraceSwitch" value="Error" /> 等于 <add name="myTraceSwitch" value="1" />The line <add name="myTraceSwitch" value="Error" /> is equivalent to <add name="myTraceSwitch" value="1" />.

         <add name="General" value="4" />  
      <trace autoflush="true" indentsize="2">  
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener, System, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" initializeData="MyListener.log" traceOutputOptions="ProcessId, LogicalOperationStack, Timestamp, ThreadId, Callstack, DateTime" />  

请参阅See also