XmlWriterTraceListener Class
Directs tracing or debugging output as XML-encoded data to a TextWriter or to a Stream, such as a FileStream.
Assembly: System (in System.dll)
System::MarshalByRefObject
System.Diagnostics::TraceListener
System.Diagnostics::TextWriterTraceListener
System.Diagnostics::XmlWriterTraceListener
| Name | Description | |
|---|---|---|
![]() | XmlWriterTraceListener(Stream^) | Initializes a new instance of the XmlWriterTraceListener class, using the specified stream as the recipient of the debugging and tracing output. |
![]() | XmlWriterTraceListener(Stream^, String^) | Initializes a new instance of the XmlWriterTraceListener class with the specified name, using the specified stream as the recipient of the debugging and tracing output. |
![]() | XmlWriterTraceListener(String^) | Initializes a new instance of the XmlWriterTraceListener class, using the specified file as the recipient of the debugging and tracing output. |
![]() | XmlWriterTraceListener(String^, String^) | Initializes a new instance of the XmlWriterTraceListener class with the specified name, using the specified file as the recipient of the debugging and tracing output. |
![]() | XmlWriterTraceListener(TextWriter^) | Initializes a new instance of the XmlWriterTraceListener class using the specified writer as the recipient of the debugging and tracing output. |
![]() | XmlWriterTraceListener(TextWriter^, String^) | Initializes a new instance of the XmlWriterTraceListener class with the specified name, using the specified writer as the recipient of the debugging and tracing output. |
| Name | Description | |
|---|---|---|
![]() | Attributes | Gets the custom trace listener attributes defined in the application configuration file.(Inherited from TraceListener.) |
![]() | Filter | Gets and sets the trace filter for the trace listener.(Inherited from TraceListener.) |
![]() | IndentLevel | Gets or sets the indent level.(Inherited from TraceListener.) |
![]() | IndentSize | Gets or sets the number of spaces in an indent.(Inherited from TraceListener.) |
![]() | IsThreadSafe | Gets a value indicating whether the trace listener is thread safe. (Inherited from TraceListener.) |
![]() | Name | Gets or sets a name for this TraceListener.(Inherited from TraceListener.) |
![]() | NeedIndent | Gets or sets a value indicating whether to indent the output.(Inherited from TraceListener.) |
![]() | TraceOutputOptions | Gets or sets the trace output options.(Inherited from TraceListener.) |
![]() | Writer | Gets or sets the text writer that receives the tracing or debugging output.(Inherited from TextWriterTraceListener.) |
| Name | Description | |
|---|---|---|
![]() | Close() | Closes the Writer for this listener so that it no longer receives tracing or debugging output.(Overrides TextWriterTraceListener::Close().) |
![]() | CreateObjRef(Type^) | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.) |
![]() | Dispose() | Releases all resources used by the TraceListener.(Inherited from TraceListener.) |
![]() | Dispose(Boolean) | This API supports the product infrastructure and is not intended to be used directly from your code. Disposes this TextWriterTraceListener object.(Inherited from TextWriterTraceListener.) |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | Fail(String^) | Emits an error message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.) |
![]() | Fail(String^, String^) | Writes trace information including an error message and a detailed error message to the file or stream.(Overrides TraceListener::Fail(String^, String^).) |
![]() | Finalize() | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.) |
![]() | Flush() | Flushes the output buffer for the Writer.(Inherited from TextWriterTraceListener.) |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetSupportedAttributes() | Gets the custom attributes supported by the trace listener.(Inherited from TraceListener.) |
![]() | GetType() | |
![]() | InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | MemberwiseClone() | |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.) |
![]() | ToString() | Returns a string that represents the current object.(Inherited from Object.) |
![]() | TraceData(TraceEventCache^, String^, TraceEventType, Int32, Object^) | Writes trace information, a data object, and event information to the file or stream.(Overrides TraceListener::TraceData(TraceEventCache^, String^, TraceEventType, Int32, Object^).) |
![]() | TraceData(TraceEventCache^, String^, TraceEventType, Int32, array<Object^>^) | Writes trace information, data objects, and event information to the file or stream.(Overrides TraceListener::TraceData(TraceEventCache^, String^, TraceEventType, Int32, array<Object^>^).) |
![]() | TraceEvent(TraceEventCache^, String^, TraceEventType, Int32) | Writes trace and event information to the listener specific output.(Inherited from TraceListener.) |
![]() | TraceEvent(TraceEventCache^, String^, TraceEventType, Int32, String^) | Writes trace information, a message, and event information to the file or stream.(Overrides TraceListener::TraceEvent(TraceEventCache^, String^, TraceEventType, Int32, String^).) |
![]() | TraceEvent(TraceEventCache^, String^, TraceEventType, Int32, String^, array<Object^>^) | Writes trace information, a formatted message, and event information to the file or stream.(Overrides TraceListener::TraceEvent(TraceEventCache^, String^, TraceEventType, Int32, String^, array<Object^>^).) |
![]() | TraceTransfer(TraceEventCache^, String^, Int32, String^, Guid) | Writes trace information including the identity of a related activity, a message, and event information to the file or stream.(Overrides TraceListener::TraceTransfer(TraceEventCache^, String^, Int32, String^, Guid).) |
![]() | Write(Object^) | Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.) |
![]() | Write(Object^, String^) | Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.) |
![]() | Write(String^) | Writes a verbatim message without any additional context information to the file or stream.(Overrides TextWriterTraceListener::Write(String^).) |
![]() | Write(String^, String^) | Writes a category name and a message to the listener you create when you implement the TraceListener class.(Inherited from TraceListener.) |
![]() | WriteIndent() | Writes the indent to the listener you create when you implement this class, and resets the NeedIndent property to false.(Inherited from TraceListener.) |
![]() | WriteLine(Object^) | Writes the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.) |
![]() | WriteLine(Object^, String^) | Writes a category name and the value of the object's ToString method to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.) |
![]() | WriteLine(String^) | Writes a verbatim message without any additional context information followed by the current line terminator to the file or stream.(Overrides TextWriterTraceListener::WriteLine(String^).) |
![]() | WriteLine(String^, String^) | Writes a category name and a message to the listener you create when you implement the TraceListener class, followed by a line terminator.(Inherited from TraceListener.) |
Note |
|---|
You must have unmanaged code permission to create an instance of the XmlWriterTraceListener class. |
The XmlWriterTraceListener 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 XmlWriterTraceListener through the application configuration file and then use the configured XmlWriterTraceListener in your application. Alternately, you can create an XmlWriterTraceListener in your code.
To configure an XmlWriterTraceListener, 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 XmlWriterTraceListener class inherits the Filter property from the base class TraceListener. The Filter 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 ShouldTrace method of the filter to determine whether to emit the trace.
Note |
|---|
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. |
Note |
|---|
Listener methods are intended to be called by methods of the Debug, Trace, and TraceSource classes. The listener methods are not intended to be called directly from application code. The XmlWriterTraceListener listener is primarily intended for use by the TraceSource class. The Write and WriteLine methods can be called by the Trace and Debug classes, and default values are provided for the XML elements that Trace and Debug 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 Callstack flag in the TraceOutputOptions 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 MachineName property. |
Correlation | ActivityID | Always present | If not specified, the default is an empty GUID. |
RelatedActivityID | Depends on the presence of the relatedActivityId parameter in the Trace method call. | The relatedActivityId parameter of the TraceTransfer method. | |
DataItem | None | Depends on the data parameter of the TraceData 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 (id). |
Execution | ProcessName | Always present. | From the TraceEventCache. |
ProcessID | Always present. | From the TraceEventCache. 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 TraceEventCache. | |
Level | None | Always present. | Parameter input (the numeric value of eventType). Parameter values greater than 255 are output as 255. |
LogicalOperationStack | None | Depends on the presence of the LogicalOperationStack flag in the TraceOutputOptions 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 TraceEventCache, the default is the current time. |
TimeStamp | None | Depends on the presence of the Timestamp flag in the TraceOutputOptions property. | From the TraceEventCache. |
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 data parameter of the TraceData method is an XPathNavigator object. If an XPathNavigator is used for the data object, the MoveToRoot method is called and the entire root node is traced as unescaped data.
Escaped character | Value |
|---|---|
& | & |
< | < |
> | > |
" | " |
\ | ' |
0xD | 
 |
0xA | 
 |
for the ability to call unmanaged code. Associated enumeration: UnmanagedCode.
Available since 2.0
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




