TraceOptions 枚举


指定要写入跟踪输出中的跟踪数据选项。Specifies trace data options to be written to the trace output.

此枚举有一个 FlagsAttribute 属性,允许按位组合成员值。

public enum class TraceOptions
public enum TraceOptions
type TraceOptions = 
Public Enum TraceOptions


Callstack 32

写入调用堆栈,该堆栈由 StackTrace 属性的返回值表示。Write the call stack, which is represented by the return value of the StackTrace property.

DateTime 2

写入日期和时间。Write the date and time.

LogicalOperationStack 1

写入逻辑操作堆栈,该堆栈由 LogicalOperationStack 属性的返回值表示。Write the logical operation stack, which is represented by the return value of the LogicalOperationStack property.

None 0

不写入任何元素。Do not write any elements.

ProcessId 8

写入进程标识,该标识由 Id 属性的返回值表示。Write the process identity, which is represented by the return value of the Id property.

ThreadId 16

写入线程标识,该标识由当前线程的 ManagedThreadId 属性的返回值表示。Write the thread identity, which is represented by the return value of the ManagedThreadId property for the current thread.

Timestamp 4

写入时间戳,该时间戳由 GetTimestamp() 方法的返回值表示。Write the timestamp, which is represented by the return value of the GetTimestamp() method.


下面的代码示例演示如何使用 TraceOptions 枚举以编程方式设置控制台跟踪侦听器的 TraceOutputOptions 属性。The following code example shows the use of the TraceOptions enumeration to programmatically set the TraceOutputOptions property for a console trace listener. 控制台跟踪侦听器是跟踪源的 Listeners 属性中枚举的侦听器之一。The console trace listener is one of the listeners enumerated in the Listeners property of a trace source. 此代码示例是为 TraceSource 类提供的更大示例的一部分。This code example is part of a larger example provided for the TraceSource class.

ts.Listeners["console"].TraceOutputOptions |= TraceOptions.Callstack;
ts.Listeners("console").TraceOutputOptions = ts.Listeners("console").TraceOutputOptions Or TraceOptions.Callstack


跟踪侦听器使用此枚举来确定应在跟踪输出中包含哪些选项或元素。This enumeration is used by trace listeners to determine which options, or elements, should be included in the trace output. 跟踪侦听器将跟踪选项存储在 TraceOutputOptions 属性中。Trace listeners store the trace options in the TraceOutputOptions property.

下面的示例演示如何使用 traceOutputOptions 特性为使用配置文件启用的 ConsoleTraceListener 指定跟踪输出选项。The following example shows the use of the traceOutputOptions attribute to specify the trace output options for a ConsoleTraceListener that is enabled using a configuration file.

    <trace autoflush="false" indentsize="4">  
        <add name="consoleListener"  
          traceOutputOptions="ProcessId, DateTime" />  

有关将跟踪侦听器添加到应用程序配置文件的详细信息,请参阅<侦听器>For details about adding trace listeners to the application configuration file, see <listeners>.

下面的类和方法不使用 TraceOptions 枚举:The TraceOptions enumeration is not used by the following classes and methods: