<trace> Element

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

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

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


Attribute Description


Optional attribute.

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


Optional attribute.

Specifies the number of spaces to indent.

Autoflush Attribute

Value Description


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


Automatically flushes the output buffer.

Child Elements

Element Description


Specifies a listener that collects, stores, and routes messages.

Parent Elements

Element Description


The root element in every configuration file used by the common language runtime and .NET Framework applications.


Specifies trace listeners that collect, store, and route messages and the level where a trace switch is set.

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.

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

Community Additions