ConsoleTraceListener 构造函数
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
初始化 ConsoleTraceListener 类的新实例。
重载
ConsoleTraceListener() |
初始化 ConsoleTraceListener 类的新实例,并将跟踪输出写入标准输出流中。 |
ConsoleTraceListener(Boolean) |
初始化 ConsoleTraceListener 类的一个新实例,并利用一个选项将跟踪输出写入标准输出流或标准错误流中。 |
ConsoleTraceListener()
- Source:
- ConsoleTraceListener.cs
- Source:
- ConsoleTraceListener.cs
- Source:
- 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)
- Source:
- ConsoleTraceListener.cs
- Source:
- ConsoleTraceListener.cs
- Source:
- 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 属性初始化为空字符串 (“”) 。
另请参阅
- TraceListener
- DefaultTraceListener
- EventLogTraceListener
- TextWriterTraceListener
- Console
- Debug
- Trace