Redaguoti

Bendrinti naudojant


<trace> Element

Contains listeners that collect, store, and route tracing messages.

<configuration>
  <system.diagnostics>
    <trace>

Syntax

<trace autoflush="true|false"
       indentsize="indent value"  
       useGlobalLock="true| false"/>  

Attributes and Elements

The following sections describe attributes, child elements, and parent elements.

Attributes

Attribute Description
autoflush Optional attribute.

Specifies whether the trace listeners automatically flush the output buffer after every write operation.
indentsize Optional attribute.

Specifies the number of spaces to indent.
useGlobalLock Optional attribute.

Indicates whether the global lock should be used.

autoflush Attribute

Value Description
false Does not automatically flush the output buffer. This is the default.
true Automatically flushes the output buffer.

useGlobalLock Attribute

Value Description
false Does not use the global lock if the listener is thread safe; otherwise, uses the global lock.
true Uses the global lock regardless of whether the listener is thread safe. This is the default.

Child Elements

Element Description
<listeners> Specifies a listener that collects, stores, and routes messages.

Parent Elements

Element Description
configuration 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.

Example

The following example shows how to use the <trace> element to add the listener MyListener to the Listeners collection. MyListener creates a file that is named MyListener.log and writes the output to the file. The useGlobalLock attribute is set to false, which causes the global lock not to be used if the trace listener is thread safe. The autoflush attribute is set to true, which causes the trace listener to write to the file regardless of whether the Trace.Flush method is called. The indentsize attribute is set to 0 (zero), which causes the listener to indent zero spaces when the Trace.Indent method is called.

<configuration>  
   <system.diagnostics>  
      <trace useGlobalLock="false" autoflush="true" indentsize="0">  
         <listeners>  
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener, system version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" initializeData="c:\myListener.log" />  
         </listeners>  
      </trace>  
   </system.diagnostics>  
</configuration>  

See also