DelimitedListTraceListener Class

Definition

将跟踪或调试输出定向到文本编写器(如流编写器)或流(如文件流)。Directs tracing or debugging output to a text writer, such as a stream writer, or to a stream, such as a file stream.

public ref class DelimitedListTraceListener : System::Diagnostics::TextWriterTraceListener
public class DelimitedListTraceListener : System.Diagnostics.TextWriterTraceListener
type DelimitedListTraceListener = class
    inherit TextWriterTraceListener
Public Class DelimitedListTraceListener
Inherits TextWriterTraceListener
Inheritance
Inheritance
DelimitedListTraceListener

Remarks

跟踪输出采用带分隔符的文本格式,该格式使用由 Delimiter 属性指定的分隔符。The trace output is in a delimited text format that uses the delimiter specified by the Delimiter property. 分隔符用于在输出行中终止每个字段。The delimiter is used to terminate each field in a line of output. 例如,若要在 Microsoft Excel 电子表格中显示跟踪输出,可以指定一个逗号(",")作为分隔符,并创建逗号分隔值(CSV)文件。For example, to display the trace output in a Microsoft Excel spreadsheet, you might specify a comma (",") as a delimiter and create a comma-separated value (CSV) file.

Important

IDisposable 接口。IDisposable interface. 在使用完类型后,您应直接或间接释放类型。When you have finished using the type, you should dispose of it either directly or indirectly. 若要直接释放类型,请在try/catch 块中调用其 Dispose 方法。To dispose of the type directly, call its Dispose method in atry/catch block. 若要间接释放类型,请使用 using(在 C# 中)或 Using(在 Visual Basic 中)等语言构造。To dispose of it indirectly, use a language construct such as using (in C#) or Using (in Visual Basic). 有关详细信息,请参阅 IDisposable 接口主题中的“使用实现 IDisposable 的对象”一节。For more information, see the "Using an Object that Implements IDisposable" section in the IDisposable interface topic.

你可以通过应用程序配置文件启用或禁用 DelimitedListTraceListener,然后在你的应用程序中使用配置的 DelimitedListTraceListenerYou can enable or disable a DelimitedListTraceListener through the application configuration file and then use the configured DelimitedListTraceListener in your application. 或者,您可以在代码中创建 DelimitedListTraceListenerAlternately, you can create a DelimitedListTraceListener in your code.

Note

DelimitedListTraceListener 仅使用名称以单词 Trace开头的方法来仅分隔发出的文本,如 DelimitedListTraceListener.TraceEventTrace.TraceWarningThe DelimitedListTraceListener delimits only text that is emitted by using the methods that have names starting with the word Trace, such as DelimitedListTraceListener.TraceEvent or Trace.TraceWarning. 使用 Debug.WriteTextWriterTraceListener.WriteLine 方法发出的跟踪数据未进行分隔。Trace data that is emitted by using the Debug.Write and TextWriterTraceListener.WriteLine methods is not delimited.

若要配置 DelimitedListTraceListener,请编辑与应用程序名称对应的配置文件。To configure a DelimitedListTraceListener, edit the configuration file that corresponds to the name of your application. 在此文件中,可以添加侦听器,设置侦听器的属性,或删除侦听器。In this file, you can add a listener, set the properties for a listener, or remove a listener. 应设置配置文件的格式,如以下示例中所示:The configuration file should be formatted as shown in the following example:

<configuration>  
  <system.diagnostics>  
    <trace autoflush="false" indentsize="4">  
      <listeners>  
        <add name="delimitedListener"   
          type="System.Diagnostics.DelimitedListTraceListener"   
          delimiter=","   
          initializeData="delimitedOutput.csv"   
          traceOutputOptions="ProcessId, DateTime" />  
      </listeners>  
    </trace>  
  </system.diagnostics>  
</configuration>  

Note

如果尝试写入正在使用或不可用的文件,则该文件名将自动以 GUID 为前缀。If you try to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID.

Note

侦听器旨在由 DebugTraceTraceSource 类的方法用来编写跟踪信息。Listeners are intended to be used by methods of the Debug, Trace, and TraceSource classes to write trace information. 除构造函数之外的侦听器方法不应在应用程序代码中直接调用。Listener methods, except for constructors, should not be called directly from application code.

Constructors

DelimitedListTraceListener(Stream)

初始化写入指定输出流的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified output stream.

DelimitedListTraceListener(Stream, String)

初始化写入指定输出流并具有指定名称的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified output stream and has the specified name.

DelimitedListTraceListener(String)

初始化写入指定文件的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified file.

DelimitedListTraceListener(String, String)

初始化写入指定文件并具有指定名称的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified file and has the specified name.

DelimitedListTraceListener(TextWriter)

初始化写入指定文本编写器的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified text writer.

DelimitedListTraceListener(TextWriter, String)

初始化写入指定文本编写器并具有指定名称的 DelimitedListTraceListener 类的新实例。Initializes a new instance of the DelimitedListTraceListener class that writes to the specified text writer and has the specified name.

Properties

Attributes

获取应用程序配置文件中定义的自定义跟踪侦听器特性。Gets the custom trace listener attributes defined in the application configuration file.

(Inherited from TraceListener)
Delimiter

获取或设置分隔列表的分隔符。Gets or sets the delimiter for the delimited list.

Filter

获取或设置跟踪侦听器的跟踪筛选器。Gets or 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

获取或设置此 TraceListener 的名称。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)

Methods

Close()

关闭 Writer,以使其不再接收跟踪或调试输出。Closes the Writer so that it no longer receives tracing or debugging output.

(Inherited from TextWriterTraceListener)
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()

释放 TraceListener 使用的所有资源。Releases all resources used by the TraceListener.

(Inherited from TraceListener)
Dispose(Boolean)

处置此 TextWriterTraceListener 对象。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)

实现 TraceListener 类时,向所创建的侦听器发出错误信息。Emits an error message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Fail(String, String)

实现 TraceListener 类时,向所创建的侦听器发出错误信息和详细错误信息。Emits an error message and a detailed error message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
Flush()

刷新 Writer 的输出缓冲区。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()

返回分隔的跟踪侦听器支持的自定义配置文件特性。Returns the custom configuration file attribute supported by the delimited trace listener.

GetSupportedAttributes()

获取跟踪侦听器支持的自定义特性。Gets the custom attributes supported by the trace listener.

(Inherited from TraceListener)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。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 output file or stream.

TraceData(TraceEventCache, String, TraceEventType, Int32, Object[])

将跟踪信息、数据对象数组和事件信息写入输出文件或流中。Writes trace information, an array of data objects, and event information to the output file or stream.

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 output file or stream.

TraceEvent(TraceEventCache, String, TraceEventType, Int32, String, Object[])

将跟踪信息、格式化对象数组和事件信息写入输出文件或流中。Writes trace information, a formatted array of objects, and event information to the output file or stream.

TraceTransfer(TraceEventCache, String, Int32, String, Guid)

向侦听器特定的输出中写入跟踪信息、消息、相关活动标识和事件信息。Writes trace information, a message, a related activity identity and event information to the listener specific output.

(Inherited from TraceListener)
Write(Object)

实现 ToString() 类时,向所创建的侦听器写入对象的 TraceListener 方法值。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)

实现 ToString() 类时,向所创建的侦听器写入类别名称和对象的 TraceListener 方法值。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)

将一条消息写入此实例的 WriterWrites a message to this instance's Writer.

(Inherited from TextWriterTraceListener)
Write(String, String)

实现 TraceListener 类时,向所创建的侦听器写入类别名称和消息。Writes a category name and a message to the listener you create when you implement the TraceListener class.

(Inherited from TraceListener)
WriteIndent()

实现此类时,向所创建的侦听器写入缩进,并将 NeedIndent 属性重置为 falseWrites the indent to the listener you create when you implement this class, and resets the NeedIndent property to false.

(Inherited from TraceListener)
WriteLine(Object)

实现 TraceListener 类时,向所创建的侦听器写入对象的 ToString() 方法值,后跟行结束符。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)

实现 TraceListener 类时,向所创建的侦听器写入类别名称和对象的 ToString() 方法值,后跟行结束符。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)

将一条消息写入该实例的 Writer,后跟行结束符。Writes a message to this instance's Writer followed by a line terminator. 默认行结束符是回车符后接一个换行符 (\r\n)。The default line terminator is a carriage return followed by a line feed (\r\n).

(Inherited from TextWriterTraceListener)
WriteLine(String, String)

实现 TraceListener 类时,向所创建的侦听器写入类别名称和消息,后跟行结束符。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)

Applies to