ConsoleTraceListener Constructors

Definition

Initializes a new instance of the ConsoleTraceListener class.

Overloads

ConsoleTraceListener()

Initializes a new instance of the ConsoleTraceListener class with trace output written to the standard output stream.

ConsoleTraceListener(Boolean)

Initializes a new instance of the ConsoleTraceListener class with an option to write trace output to the standard output stream or the standard error stream.

ConsoleTraceListener()

Source:
ConsoleTraceListener.cs
Source:
ConsoleTraceListener.cs
Source:
ConsoleTraceListener.cs

Initializes a new instance of the ConsoleTraceListener class with trace output written to the standard output stream.

C#
public ConsoleTraceListener();

Examples

The following code example initializes a ConsoleTraceListener object for the specified Console output stream and adds it to the trace listener collection. This code example is part of a larger example provided for the ConsoleTraceListener class.

C#
// Define a trace listener to direct trace output from this method
// to the console.
ConsoleTraceListener consoleTracer;

// Check the command line arguments to determine which
// console stream should be used for trace output.
if ((CmdArgs.Length>0)&&(CmdArgs[0].ToString().ToLower().Equals("/stderr")))
    // Initialize the console trace listener to write
    // trace output to the standard error stream.
{
    consoleTracer = new ConsoleTraceListener(true);
}
else
{
    // Initialize the console trace listener to write
    // trace output to the standard output stream.
    consoleTracer = new ConsoleTraceListener();
}
// Set the name of the trace listener, which helps identify this
// particular instance within the trace listener collection.
consoleTracer.Name = "mainConsoleTracer";

// Write the initial trace message to the console trace listener.
consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Starting output to trace listener.");

// Add the new console trace listener to
// the collection of trace listeners.
Trace.Listeners.Add(consoleTracer);

Remarks

This constructor initializes a ConsoleTraceListener object to write messages to the Console.Out stream. Its Name property is initialized to an empty string ("").

See also

Applies to

.NET 10 och andra versioner
Produkt Versioner
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

ConsoleTraceListener(Boolean)

Source:
ConsoleTraceListener.cs
Source:
ConsoleTraceListener.cs
Source:
ConsoleTraceListener.cs

Initializes a new instance of the ConsoleTraceListener class with an option to write trace output to the standard output stream or the standard error stream.

C#
public ConsoleTraceListener(bool useErrorStream);

Parameters

useErrorStream
Boolean

true to write tracing and debugging output to the standard error stream; false to write tracing and debugging output to the standard output stream.

Examples

The following code example initializes a ConsoleTraceListener object for the specified Console output stream and adds it to the trace listener collection. This code example is part of a larger example provided for the ConsoleTraceListener class.

C#
// Define a trace listener to direct trace output from this method
// to the console.
ConsoleTraceListener consoleTracer;

// Check the command line arguments to determine which
// console stream should be used for trace output.
if ((CmdArgs.Length>0)&&(CmdArgs[0].ToString().ToLower().Equals("/stderr")))
    // Initialize the console trace listener to write
    // trace output to the standard error stream.
{
    consoleTracer = new ConsoleTraceListener(true);
}
else
{
    // Initialize the console trace listener to write
    // trace output to the standard output stream.
    consoleTracer = new ConsoleTraceListener();
}
// Set the name of the trace listener, which helps identify this
// particular instance within the trace listener collection.
consoleTracer.Name = "mainConsoleTracer";

// Write the initial trace message to the console trace listener.
consoleTracer.WriteLine(DateTime.Now.ToString()+" ["+consoleTracer.Name+"] - Starting output to trace listener.");

// Add the new console trace listener to
// the collection of trace listeners.
Trace.Listeners.Add(consoleTracer);

Remarks

This constructor initializes a ConsoleTraceListener object to write messages to either the Console.Out or the Console.Error stream. Its Name property is initialized to an empty string ("").

See also

Applies to

.NET 10 och andra versioner
Produkt Versioner
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1