System 2.0.0.0 4.0.0.0 System.Diagnostics.TextWriterTraceListener

You must have unmanaged code permission to create an instance of the class.

The class converts tracing and debugging information into an XML-encoded text stream. The description of the XML output is shown in the tables that follow. You can use the Service Trace Viewer Tool (SvcTraceViewer.exe) to display the XML output.

You can enable or disable an through the application configuration file and then use the configured in your application. Alternately, you can create an in your code.

To configure an , edit the configuration file that corresponds to the name of your application. In this file, you can add or remove a listener, set the properties for a listener, or remove listeners. The configuration file should be formatted like the following example.

`<configuration> <system.diagnostics> <trace autoflush="false" indentsize="4"> <listeners> <add name="xmlListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="xmlOutput.xml" traceOutputOptions="ProcessId, DateTime" /> <remove name="Default" /> </listeners> </trace> </system.diagnostics> </configuration>`

The class inherits the property from the base class . The property allows an additional level of trace output filtering at the listener. If there is a filter present, the Trace methods of the trace listener call the method of the filter to determine whether to emit the trace.

If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID.

Listener methods are intended to be called by methods of the , , and classes. The listener methods are not intended to be called directly from application code. The listener is primarily intended for use by the class. The and methods can be called by the and classes, and default values are provided for the XML elements that and do not supply values for.

The following table describes the elements and attributes of the XML output.

Element

Attributes

Output

Notes

CallStack

None

Depends on the presence of the flag in the property.

Special characters such as > or < are replaced with escape sequences. See the escaped character translation table that follows.

Computer

None

Always present.

The value of the property.

Correlation

ActivityID

Always present

If not specified, the default is an empty GUID.

RelatedActivityID

Depends on the presence of the parameter in the Trace method call.

The parameter of the method.

DataItem

None

Depends on the parameter of the method.

This element can contain an array of elements or one element, so the values are written as a set of DataItem nodes under the TraceData element.

The data output uses the ToString method of the passed-in data objects.

EventID

None

Always present.

Parameter input ().

Execution

ProcessName

Always present.

From the .

ProcessID

Always present.

From the . On Windows 98 and Windows Me operating systems, if ProcessID is greater than 2,147,483,647 it is a positive representation of a negative number and should be converted to obtain the correct process identifier.

ThreadID

Always present.

From the .

Level

None

Always present.

Parameter input (the numeric value of ). Parameter values greater than 255 are output as 255.

LogicalOperationStack

None

Depends on the presence of the flag in the property.

There can be more than one logical operation, so the values are written as LogicalOperation nodes under the LogicalOperationStack element.

Message

None

Depends on the presence of a message in the Trace method call.

This element is a formatted message if formatting arguments are provided.

Source

Name

Always present.

Parameter input.

SubType

Name

Always present.

Parameter input.

TimeCreated

SystemTime

Always present.

If not present in the , the default is the current time.

TimeStamp

None

Depends on the presence of the flag in the property.

From the .

Type

None

Always present.

Always the value 3.

The following table shows the characters that are escaped in the XML output. Escaping occurs in all the elements and attributes with the exception of the DataItem element, which is not escaped if the object passed to the parameter of the method is an object. If an is used for the data object, the method is called and the entire root node is traced as unescaped data.

Escaped character

Value

&

&amp;

<

&lt;

>

&gt;

"

&quot;

\

&apos;

0xD

&#xD;

0xA

&#xA;

Directs tracing or debugging output as XML-encoded data to a or to a , such as a .

- Constructor
  2.0.0.0
  4.0.0.0

  The property is initialized to an empty string ("").

  Initializes a new instance of the class, using the specified stream as the recipient of the debugging and tracing output.

  A that represents the stream the trace listener writes to.
- Constructor
  2.0.0.0
  4.0.0.0

  The property is initialized to an empty string ("").

  Initializes a new instance of the class using the specified writer as the recipient of the debugging and tracing output.

  A that receives the output from the trace listener.
- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes a new instance of the class for the specified file on the specified path, using encoding. If the file exists, it is appended to. If the file does not exist, a new file is created.

  To reduce the chance of an exception, any character that might invalidate the output is replaced with a "?" character.

  The property is initialized to an empty string ("").

  Initializes a new instance of the class, using the specified file as the recipient of the debugging and tracing output.

  The name of the file to write to.
- Constructor
  2.0.0.0
  4.0.0.0
  To be added.

  This constructor initializes the property to the parameter value or to an empty string ("") if the parameter is null. The name can be used as an index into the collection to programmatically change the properties for the listener. For example, the following code sets the property for an instance of whose property is "xmlListener".

  ((XmlWriterTraceListener)Trace.Listeners["xmlListener"]).TraceOutputOptions = TraceOptions.Timestamp

  Initializes a new instance of the class with the specified name, using the specified stream as the recipient of the debugging and tracing output.

  The name of the new instance.
- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes the property to the parameter value or to an empty string ("") if the parameter is null. The name can be used as an index into the collection to programmatically change the properties for the listener. For example, the following code sets the property for an instance of whose property is "xmlListener".

  ((XmlWriterTraceListener)Trace.Listeners["xmlListener"]).TraceOutputOptions = TraceOptions.Timestamp.

  Initializes a new instance of the class with the specified name, using the specified writer as the recipient of the debugging and tracing output.

  A that receives the output from the trace listener.
  The name of the new instance.
- Constructor
  2.0.0.0
  4.0.0.0

  This constructor initializes a new instance of the class for the specified file on the specified path, using encoding. If the file exists, it is appended to. If the file does not exist, a new file is created.

  To reduce the chance of an exception, any character that might invalidate the output is replaced with a "?" character.

  The property is set to the parameter value or to an empty string ("") if the parameter is null. The name can be used as an index into the collection to programmatically change the properties for the listener. For example, the following code sets the property for an instance of whose property is "xmlListener".

  ((XmlWriterTraceListener)Trace.Listeners["xmlListener"]).TraceOutputOptions = TraceOptions.Timestamp.

  Initializes a new instance of the class with the specified name, using the specified file as the recipient of the debugging and tracing output.

  The name of the file to write to.
  The name of the new instance.
- Method
  2.0.0.0
  4.0.0.0
  System.Void To be added.

  Closes the for this listener so that it no longer receives tracing or debugging output.

- Method
  2.0.0.0
  4.0.0.0
  System.Void `` ``

  The default behavior is to display the message and detailed message in a message box when the application is running in user-interface mode, and to the instances in the collection. By default, the collection contains an instance of . You can customize this behavior by adding or removing a from the collection.

  Writes trace information including an error message and a detailed error message to the file or stream.

  The error message to write. The detailed error message to append to the error message.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` `` ``

  The , , , and parameters are used in the header and footer of the trace. The parameter is converted to an unsigned integer before writing, so a negative value is written as a large positive integer. The parameter is written as a DataItem node in the TraceData element. The ToString method of the data object is used to convert the object to a string.

  This method is not intended to be called directly by application code. It is called by methods of the , , and classes to write trace data.

  Writes trace information, a data object, and event information to the file or stream.

  A that contains the current process ID, thread ID, and stack trace information. The source name. One of the values. A numeric identifier for the event. A data object to emit.
- Method
  2.0.0.0
  4.0.0.0
  System.MonoLimitation("level is not always correct")
  System.Void `` `` `` `` `System.ParamArray`

  The , , , and parameters are used in the header and footer of the trace. The parameter is converted to an unsigned integer before writing, so a negative value is written as a large positive integer. The objects in the parameter array are written as DataItem nodes in the TraceData element. The ToString method of each data object is used to convert the object to a string.

  This method is not intended to be called directly by application code. It is called by methods of the , , and classes to write trace data.

  Writes trace information, data objects, and event information to the file or stream.

  A that contains the current process ID, thread ID, and stack trace information. The source name. One of the values. A numeric identifier for the event. An array of data objects to emit.
- Method
  2.0.0.0
  4.0.0.0
  System.MonoLimitation("level is not always correct")
  System.Void `` `` `` `` ``

  The , , , and parameters are used in the header and footer of the trace. The parameter is converted to an unsigned integer before writing, so a negative value is written as a large positive integer. The parameter is written as the Message element.

  This method is not intended to be called directly by application code. It is called by methods of the , , and classes to write trace data.

  Writes trace information, a message, and event information to the file or stream.

  A that contains the current process ID, thread ID, and stack trace information. The source name. One of the values. A numeric identifier for the event. The message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.MonoLimitation("level is not always correct")
  System.Void `` `` `` `` `` `System.ParamArray`

  The , , , and parameters are used in the header and footer of the trace. The parameter is converted to an unsigned integer before writing, so a negative value is written as a large positive integer. The method is called, passing in the string and array as parameters, to format the object array as the Message element.

  This method is not intended to be called directly by application code. It is called by methods of the , , and classes to write trace data.

  Writes trace information, a formatted message, and event information to the file or stream.

  A that contains the current process ID, thread ID, and stack trace information. The source name. One of the values. A numeric identifier for the event. A format string that contains zero or more format items that correspond to objects in the array. An object array containing zero or more objects to format.
- Method
  2.0.0.0
  4.0.0.0
  System.Void `` `` `` `` ``

  The method is used for the correlation of related traces. The , , , and parameters are used in the header and footer of the trace. The parameter is converted to an unsigned integer before writing, so a negative value is written as a large positive integer. The parameter is written as the Message element. The method is called to convert the value to a "B" formatted string, which appears in the header. The SubTypeName element in the footer identifies the trace event type as a .

  The method is not intended to be called by application code. It is intended to be called by a object to emit the trace information for its method.

  Writes trace information including the identity of a related activity, a message, and event information to the file or stream.

  A that contains the current process ID, thread ID, and stack trace information. The source name. A numeric identifier for the event. A trace message to write. A structure that identifies a related activity.
- Method
  2.0.0.0
  4.0.0.0
  System.Void ``

  Use the method to include context information in the log output.

  Writes a verbatim message without any additional context information to the file or stream.

  The message to write.
- Method
  2.0.0.0
  4.0.0.0
  System.MonoLimitation("level is not always correct")
  System.Void ``

  Use the method to include context information in the log output.

  Writes a verbatim message without any additional context information followed by the current line terminator to the file or stream.

  The message to write.