共用方式為


ConsoleTraceListener 建構函式

定義

初始化 ConsoleTraceListener 類別的新執行個體。

多載

ConsoleTraceListener()

初始化 ConsoleTraceListener 類別的新執行個體,附追蹤輸出寫入至標準輸出資料流。

ConsoleTraceListener(Boolean)

初始化 ConsoleTraceListener 類別的新執行個體,附寫入追蹤輸出至標準輸出資料流或標準錯誤資料流的選項。

ConsoleTraceListener()

來源:
ConsoleTraceListener.cs
來源:
ConsoleTraceListener.cs
來源:
ConsoleTraceListener.cs

初始化 ConsoleTraceListener 類別的新執行個體,附追蹤輸出寫入至標準輸出資料流。

public:
 ConsoleTraceListener();
public ConsoleTraceListener ();
Public Sub New ()

範例

下列程式代碼範例會 ConsoleTraceListener 初始化指定 Console 輸出數據流的物件,並將它新增至追蹤接聽程式集合。 此程式代碼範例是針對 類別提供的較大範例的 ConsoleTraceListener 一部分。

// 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);
' Define a trace listener to direct trace output from this method
' to the console.
Dim consoleTracer As ConsoleTraceListener

' Check the command line arguments to determine which
' console stream should be used for trace output.
If (CmdArgs.Length > 0) AndAlso _
   (CmdArgs(0).ToLower.Equals("/stderr")) Then
    ' 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
End If
' 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)

備註

這個建構函式會 ConsoleTraceListener 初始化 物件,以將訊息 Console.Out 寫入數據流。 其 Name 屬性會初始化為空字串 (“”) 。

另請參閱

適用於

ConsoleTraceListener(Boolean)

來源:
ConsoleTraceListener.cs
來源:
ConsoleTraceListener.cs
來源:
ConsoleTraceListener.cs

初始化 ConsoleTraceListener 類別的新執行個體,附寫入追蹤輸出至標準輸出資料流或標準錯誤資料流的選項。

public:
 ConsoleTraceListener(bool useErrorStream);
public ConsoleTraceListener (bool useErrorStream);
new System.Diagnostics.ConsoleTraceListener : bool -> System.Diagnostics.ConsoleTraceListener
Public Sub New (useErrorStream As Boolean)

參數

useErrorStream
Boolean

如果是 true,就表示要將追蹤與偵錯輸出寫入至標準錯誤資料流;如果是 false,則表示要寫入追蹤與偵錯輸出至標準輸出資料流。

範例

下列程式代碼範例會 ConsoleTraceListener 初始化指定 Console 輸出數據流的物件,並將它新增至追蹤接聽程式集合。 此程式代碼範例是針對 類別提供的較大範例的 ConsoleTraceListener 一部分。

// 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);
' Define a trace listener to direct trace output from this method
' to the console.
Dim consoleTracer As ConsoleTraceListener

' Check the command line arguments to determine which
' console stream should be used for trace output.
If (CmdArgs.Length > 0) AndAlso _
   (CmdArgs(0).ToLower.Equals("/stderr")) Then
    ' 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
End If
' 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)

備註

這個建構函式會 ConsoleTraceListener 初始化 物件,以將訊息 Console.Out 寫入 或 Console.Error 數據流。 其 Name 屬性會初始化為空字串 (“”) 。

另請參閱

適用於