Share via


<trace> Element 

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

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

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.

Autoflush Attribute

Value Description

false

Does not automatically flush the output buffer. This is the default.

true

Automatically flushes the output buffer.

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 called MyListener.log and writes the output to the file. 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, which causes the listener to indent zero spaces when the Trace.Indent method is called.

<configuration>
   <system.diagnostics>
      <trace 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

Reference

Trace and Debug Settings Schema
TraceListener Class
DefaultTraceListener Class
TextWriterTraceListener Class
EventLogTraceListener Class