TraceSource 构造函数

定义

初始化 TraceSource 类的新实例。Initializes a new instance of the TraceSource class.

重载

TraceSource(String)

使用指定的源名称初始化 TraceSource 类的新实例。Initializes a new instance of the TraceSource class, using the specified name for the source.

TraceSource(String, SourceLevels)

使用源的指定名称和执行跟踪的默认源级别初始化 TraceSource 类的新实例。Initializes a new instance of the TraceSource class, using the specified name for the source and the default source level at which tracing is to occur.

TraceSource(String)

使用指定的源名称初始化 TraceSource 类的新实例。Initializes a new instance of the TraceSource class, using the specified name for the source.

public:
 TraceSource(System::String ^ name);
public TraceSource (string name);
new System.Diagnostics.TraceSource : string -> System.Diagnostics.TraceSource
Public Sub New (name As String)

参数

name
String

源的名称(通常为应用程序的名称)。The name of the source (typically, the name of the application).

例外

namenullname is null.

name 为空字符串 ("")。name is an empty string ("").

示例

下面的代码示例演示 TraceSource 如何使用构造函数创建新的 TraceSource 对象。The following code example shows the use of the TraceSource constructor to create a new TraceSource object. 此代码示例是为类提供的更大示例的一部分 TraceSourceThis code example is part of a larger example provided for the TraceSource class.

// Initialize the trace source.
static TraceSource ts = new TraceSource("TraceTest");
' Initialize the trace source.
Private Shared ts As New TraceSource("TraceTest")

注解

源名称用于标识跟踪。The source name is used to identify traces. 使用它 SourceFilter 来确定跟踪侦听器是否应生成跟踪。It is used by a SourceFilter to determine whether a trace listener should produce the trace. 建议的做法是使用应用程序的名称作为源名称。The recommended practice is to use the name of the application for the source name.

备注

不需要为 TraceSource 每个跟踪请求创建新的实例。It is not necessary to create a new TraceSource instance for each trace request. 创建一个 TraceSource 实例,并将其用于应用程序的所有跟踪请求。Create one TraceSource instance and use it for all trace requests for the application.

适用于

产品 Introduced

TraceSource(String, SourceLevels)

使用源的指定名称和执行跟踪的默认源级别初始化 TraceSource 类的新实例。Initializes a new instance of the TraceSource class, using the specified name for the source and the default source level at which tracing is to occur.

public:
 TraceSource(System::String ^ name, System::Diagnostics::SourceLevels defaultLevel);
public TraceSource (string name, System.Diagnostics.SourceLevels defaultLevel);
new System.Diagnostics.TraceSource : string * System.Diagnostics.SourceLevels -> System.Diagnostics.TraceSource
Public Sub New (name As String, defaultLevel As SourceLevels)

参数

name
String

源的名称,通常为应用程序的名称。The name of the source, typically the name of the application.

defaultLevel
SourceLevels

枚举的按位组合,指定要跟踪的默认源级别。A bitwise combination of the enumeration values that specifies the default source level at which to trace.

例外

namenullname is null.

name 为空字符串 ("")。name is an empty string ("").

注解

源名称用于标识跟踪。The source name is used to identify traces. 可以使用它 SourceSwitch 来确定是否发生跟踪,并使用 SourceFilter 来确定是否生成跟踪。It can be used by a SourceSwitch to determine if tracing is to occur and by a SourceFilter to determine whether to produce the trace. 使用默认源级别 EventTypeFilter 来确定是否基于要跟踪的消息的源级别进行跟踪。The default source level is used by an EventTypeFilter to determine if tracing is to occur based on the source level of the message to be traced.

备注

不需要为 TraceSource 每个跟踪请求创建新的实例。It is not necessary to create a new TraceSource instance for each trace request. 创建一个 TraceSource 实例,并将其用于应用程序的所有跟踪请求。Create one TraceSource instance and use it for all trace requests for the application.

适用于

产品 Introduced