Upraviť

Zdieľať cez


TraceSource Constructors

Definition

Initializes a new instance of the TraceSource class.

Overloads

TraceSource(String)

Initializes a new instance of the TraceSource class, using the specified name for the source.

TraceSource(String, SourceLevels)

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)

Source:
TraceSource.cs
Source:
TraceSource.cs
Source:
TraceSource.cs

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)

Parameters

name
String

The name of the source (typically, the name of the application).

Exceptions

name is null.

name is an empty string ("").

Examples

The following code example shows the use of the TraceSource constructor to create a new TraceSource object. This 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")

Remarks

The source name is used to identify traces. 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.

Note

It is not necessary to create a new TraceSource instance for each trace request. Create one TraceSource instance and use it for all trace requests for the application.

Applies to

TraceSource(String, SourceLevels)

Source:
TraceSource.cs
Source:
TraceSource.cs
Source:
TraceSource.cs

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)

Parameters

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.

Exceptions

name is null.

name is an empty string ("").

Remarks

The source name is used to identify traces. 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. 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.

Note

It is not necessary to create a new TraceSource instance for each trace request. Create one TraceSource instance and use it for all trace requests for the application.

Applies to