<trace> Element
Contains listeners that collect, store, and route tracing messages.
<configuration>
<system.diagnostics>
<trace>
<trace autoflush="true|false"
indentsize="indent value"/>
Optional Attributes
Attribute | Description |
---|---|
autoflush | Specifies whether the trace listeners automatically flush the output buffer after every write operation. Specify one of the following values:
|
indentsize | Specifies the number of spaces to indent. |
Child Elements
Element | Description |
---|---|
<listeners> | Specifies a listener that collects, stores, and routes messages. |
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, Version, Culture, PublicKeyToken"
initializeData="MyListener.log"/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
Configuration File
This element can be used in the machine configuration file (Machine.config) and the application configuration file.
See Also
Trace and Debug Settings Schema | TraceListener Class | DefaultTraceListener Class | TextWriterTraceListener Class | EventLogTraceListener Class