XmlWriterTraceListener Constructor (String, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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.

Namespace:   System.Diagnostics
Assembly:  System (in System.dll)

public XmlWriterTraceListener(
	string filename,
	string name


Type: System.String

The name of the file to write to.

Type: System.String

The name of the new instance.

Exception Condition

stream is null.

This constructor initializes a new instance of the StreamWriter class for the specified file on the specified path, using UTF8 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 Name property is set to the name parameter value or to an empty string ("") if the name parameter is null. The name can be used as an index into the Trace.Listeners collection to programmatically change the properties for the listener. For example, the following code sets the TraceOutputOptions property for an instance of XmlWriterTraceListener whose Name property is "xmlListener".

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


for the ability to call unmanaged code. Associated enumeration: UnmanagedCode.

.NET Framework
Available since 2.0
Return to top