TraceSource TraceSource TraceSource TraceSource Class

定义

提供一组方法和属性,利用这些方法和属性,应用程序可以跟踪代码的执行并将跟踪消息和它们的源关联起来。Provides a set of methods and properties that enable applications to trace the execution of code and associate trace messages with their source.

public ref class TraceSource
public class TraceSource
type TraceSource = class
Public Class TraceSource
继承
TraceSourceTraceSourceTraceSourceTraceSource

示例

下面的代码示例演示如何使用TraceSource类将跟踪转发到侦听器。The following code example shows the use of the TraceSource class to forward traces to listeners. 该示例还演示了开关和筛选器的用法。The example also demonstrates switch and filter usage.

/////////////////////////////////////////////////////////////////////////////////
//
// NAME     TraceSource2.cpp : main project file
//
/////////////////////////////////////////////////////////////////////////////////



// The following configuration file can be used with this sample.
// When using a configuration file #define ConfigFile.
//            <source name="TraceTest" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
//                    <add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false" />
//                    <remove name ="Default" />
//            <!-- You can set the level at which tracing is to occur -->
//            <add name="SourceSwitch" value="Warning" />
//            <!-- You can turn tracing off -->
//            <!--add name="SourceSwitch" value="Off" -->
//        <trace autoflush="true" indentsize="4"></trace>

#define TRACE
//#define ConfigFile

#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Diagnostics;
using namespace System::Reflection;
using namespace System::IO;
using namespace System::Security::Permissions;

void DisplayProperties(TraceSource^ ts);  // Forward Declaration


int main()
{
    TraceSource^ ts = gcnew TraceSource("TraceTest");

    try
        {
        // Initialize trace switches.
#if(!ConfigFile)
        SourceSwitch^ sourceSwitch = gcnew SourceSwitch("SourceSwitch", "Verbose");
		ts->Switch = sourceSwitch;
        int idxConsole = ts->Listeners->Add(gcnew System::Diagnostics::ConsoleTraceListener());
        ts->Listeners[idxConsole]->Name = "console";
#endif
        DisplayProperties(ts);
        ts->Listeners["console"]->TraceOutputOptions |= TraceOptions::Callstack;
        ts->TraceEvent(TraceEventType::Warning, 1);
        ts->Listeners["console"]->TraceOutputOptions = TraceOptions::DateTime;
        // Issue file not found message as a warning.
        ts->TraceEvent(TraceEventType::Warning, 2, "File Test not found");
        // Issue file not found message as a verbose event using a formatted string.
        ts->TraceEvent(TraceEventType::Verbose, 3, "File {0} not found.", "test");
        // Issue file not found message as information.
        ts->TraceInformation("File {0} not found.", "test");
        ts->Listeners["console"]->TraceOutputOptions |= TraceOptions::LogicalOperationStack;
        // Issue file not found message as an error event.
        ts->TraceEvent(TraceEventType::Error, 4, "File {0} not found.", "test");

        // Test the filter on the ConsoleTraceListener.
        ts->Listeners["console"]->Filter = gcnew SourceFilter("No match");
        ts->TraceData(TraceEventType::Error, 5,
            "SourceFilter should reject this message for the console trace listener.");
        ts->Listeners["console"]->Filter = gcnew SourceFilter("TraceTest");
        ts->TraceData(TraceEventType::Error, 6,
            "SourceFilter should let this message through on the console trace listener.");
        ts->Listeners["console"]->Filter = nullptr;

        // Use the TraceData method. 
        ts->TraceData(TraceEventType::Warning, 7, gcnew array<Object^>{ "Message 1", "Message 2" });

        // Activity tests.
        ts->TraceEvent(TraceEventType::Start, 9, "Will not appear until the switch is changed.");
        ts->Switch->Level = SourceLevels::ActivityTracing | SourceLevels::Critical;
        ts->TraceEvent(TraceEventType::Suspend, 10, "Switch includes ActivityTracing, this should appear");
        ts->TraceEvent(TraceEventType::Critical, 11, "Switch includes Critical, this should appear");
        ts->Flush();
        ts->Close();
        Console::WriteLine("Press enter key to exit.");
        Console::Read();
        }
    catch (Exception ^e)
        {
         // Catch any unexpected exception.
         Console::WriteLine("Unexpected exception: " + e->ToString());
         Console::Read();
        }
}


void DisplayProperties(TraceSource^ ts)
{
    Console::WriteLine("TraceSource name = " + ts->Name);
//    Console::WriteLine("TraceSource switch level = " + ts->Switch->Level);         // error C3063: operator '+': all operands must have the same enumeration type
    Console::WriteLine("TraceSource switch level = {0}", ts->Switch->Level);         //  SUCCESS:  does compile.  Weird
    Console::WriteLine("TraceSource Attributes Count " + ts->Attributes->Count);     //  SUCCESS:  also compiles.  Really weird
    Console::WriteLine("TraceSource Attributes Count = {0}", ts->Attributes->Count); //  SUCCESS:  okay, I give up.  Somebody call me a cab.

    Console::WriteLine("TraceSource switch = " + ts->Switch->DisplayName);
    array<SwitchAttribute^>^ switches = SwitchAttribute::GetAll(TraceSource::typeid->Assembly);

    for (int i = 0; i < switches->Length; i++)
        { 
        Console::WriteLine("Switch name = " + switches[i]->SwitchName);
        Console::WriteLine("Switch type = " + switches[i]->SwitchType);
        }

#if(ConfigFile)
            // Get the custom attributes for the TraceSource.
            Console::WriteLine("Number of custom trace source attributes = "
                + ts.Attributes.Count);
            foreach (DictionaryEntry de in ts.Attributes)
                Console::WriteLine("Custom trace source attribute = "
                    + de.Key + "  " + de.Value);
            // Get the custom attributes for the trace source switch.
            foreach (DictionaryEntry de in ts.Switch.Attributes)
                Console::WriteLine("Custom switch attribute = "
                    + de.Key + "  " + de.Value);
#endif
       Console::WriteLine("Number of listeners = " + ts->Listeners->Count);
       for each (TraceListener ^ traceListener in ts->Listeners)
           {
           Console::Write("TraceListener: " + traceListener->Name + "\t");
           // The following output can be used to update the configuration file.
           Console::WriteLine("AssemblyQualifiedName = " +
               (traceListener->GetType()->AssemblyQualifiedName));
           }
}
// The following configuration file can be used with this sample.
// When using a configuration file #define ConfigFile.
//            <source name="TraceTest" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
//                    <add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false" />
//                    <remove name ="Default" />
//            <!-- You can set the level at which tracing is to occur -->
//            <add name="SourceSwitch" value="Warning" />
//            <!-- You can turn tracing off -->
//            <!--add name="SourceSwitch" value="Off" -->
//        <trace autoflush="true" indentsize="4"></trace>
#define TRACE
//#define ConfigFile

using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.IO;
using System.Security.Permissions;

namespace Testing
{
    class TraceTest
    {
        // Initialize the trace source.
        static TraceSource ts = new TraceSource("TraceTest");
        [SwitchAttribute("SourceSwitch", typeof(SourceSwitch))]
        static void Main()
        {
            try
            {
                // Initialize trace switches.
#if(!ConfigFile)
                SourceSwitch sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose");
                ts.Switch = sourceSwitch;
                int idxConsole = ts.Listeners.Add(new System.Diagnostics.ConsoleTraceListener());
                ts.Listeners[idxConsole].Name = "console";
#endif
                DisplayProperties(ts);
                ts.Listeners["console"].TraceOutputOptions |= TraceOptions.Callstack;
                ts.TraceEvent(TraceEventType.Warning, 1);
                ts.Listeners["console"].TraceOutputOptions = TraceOptions.DateTime;
                // Issue file not found message as a warning.
                ts.TraceEvent(TraceEventType.Warning, 2, "File Test not found");
                // Issue file not found message as a verbose event using a formatted string.
                ts.TraceEvent(TraceEventType.Verbose, 3, "File {0} not found.", "test");
                // Issue file not found message as information.
                ts.TraceInformation("File {0} not found.", "test");
                ts.Listeners["console"].TraceOutputOptions |= TraceOptions.LogicalOperationStack;
                // Issue file not found message as an error event.
                ts.TraceEvent(TraceEventType.Error, 4, "File {0} not found.", "test");
                // Test the filter on the ConsoleTraceListener.
                ts.Listeners["console"].Filter = new SourceFilter("No match");
                ts.TraceData(TraceEventType.Error, 5,
                    "SourceFilter should reject this message for the console trace listener.");
                ts.Listeners["console"].Filter = new SourceFilter("TraceTest");
                ts.TraceData(TraceEventType.Error, 6,
                    "SourceFilter should let this message through on the console trace listener.");
                ts.Listeners["console"].Filter = null;
                // Use the TraceData method. 
                ts.TraceData(TraceEventType.Warning, 7, new object());
                ts.TraceData(TraceEventType.Warning, 8, new object[] { "Message 1", "Message 2" });
                // Activity tests.
                ts.TraceEvent(TraceEventType.Start, 9, "Will not appear until the switch is changed.");
                ts.Switch.Level = SourceLevels.ActivityTracing | SourceLevels.Critical;
                ts.TraceEvent(TraceEventType.Suspend, 10, "Switch includes ActivityTracing, this should appear");
                ts.TraceEvent(TraceEventType.Critical, 11, "Switch includes Critical, this should appear");
                ts.Flush();
                ts.Close();
                Console.WriteLine("Press any key to exit.");
                Console.Read();
            }
            catch (Exception e)
            {
                // Catch any unexpected exception.
                Console.WriteLine("Unexpected exception: " + e.ToString());
                Console.Read();
            }
        }
        public static void DisplayProperties(TraceSource ts)
        {
            Console.WriteLine("TraceSource name = " + ts.Name);
            Console.WriteLine("TraceSource switch level = " + ts.Switch.Level);
            Console.WriteLine("TraceSource switch = " + ts.Switch.DisplayName);
            SwitchAttribute[] switches = SwitchAttribute.GetAll(typeof(TraceTest).Assembly);
            for (int i = 0; i < switches.Length; i++)
            {
                Console.WriteLine("Switch name = " + switches[i].SwitchName);
                Console.WriteLine("Switch type = " + switches[i].SwitchType);
            }
#if(ConfigFile)
            // Get the custom attributes for the TraceSource.
            Console.WriteLine("Number of custom trace source attributes = "
                + ts.Attributes.Count);
            foreach (DictionaryEntry de in ts.Attributes)
                Console.WriteLine("Custom trace source attribute = "
                    + de.Key + "  " + de.Value);
            // Get the custom attributes for the trace source switch.
            foreach (DictionaryEntry de in ts.Switch.Attributes)
                Console.WriteLine("Custom switch attribute = "
                    + de.Key + "  " + de.Value);
#endif
            Console.WriteLine("Number of listeners = " + ts.Listeners.Count);
            foreach (TraceListener traceListener in ts.Listeners)
            {
                Console.Write("TraceListener: " + traceListener.Name + "\t");
                // The following output can be used to update the configuration file.
                Console.WriteLine("AssemblyQualifiedName = " +
                    (traceListener.GetType().AssemblyQualifiedName));
            }
        }
    }
}
' The following configuration file can be used with this sample.
' When using a configuration file #define ConfigFile.
'            <source name="TraceTest" switchName="SourceSwitch" switchType="System.Diagnostics.SourceSwitch" >
'                    <add name="console" type="System.Diagnostics.ConsoleTraceListener" initializeData="false" />
'                    <remove name ="Default" />
'            <!-- You can set the level at which tracing is to occur -->
'            <add name="SourceSwitch" value="Warning" />
'            <!-- You can turn tracing off -->
'            <!--add name="SourceSwitch" value="Off" -->
'        <trace autoflush="true" indentsize="4"></trace>
#Const TRACE = True
'#Const ConfigFile = True

Imports System.Collections
Imports System.Diagnostics
Imports System.Reflection
Imports System.IO
Imports System.Security.Permissions



Class TraceTest
    ' Initialize the trace source.
    Private Shared ts As New TraceSource("TraceTest")
    <SwitchAttribute("SourceSwitch", GetType(SourceSwitch))> _
    Shared Sub Main()
        Try
            ' Initialize trace switches.
#If (ConfigFile = False) Then
            Dim sourceSwitch As New SourceSwitch("SourceSwitch", "Verbose")
            ts.Switch = sourceSwitch
            Dim idxConsole As New Integer()
            idxConsole = ts.Listeners.Add(New System.Diagnostics.ConsoleTraceListener())
            ts.Listeners(idxConsole).Name = "console"
#End If
            DisplayProperties(ts)
            ts.Listeners("console").TraceOutputOptions = ts.Listeners("console").TraceOutputOptions Or TraceOptions.Callstack
            ts.TraceEvent(TraceEventType.Warning, 1)
            ts.Listeners("console").TraceOutputOptions = TraceOptions.DateTime
            ' Issue file not found message as a warning.
            ts.TraceEvent(TraceEventType.Warning, 2, "File Test not found")
            ' Issue file not found message as a verbose event using a formatted string.
            ts.TraceEvent(TraceEventType.Verbose, 3, "File {0} not found.", "test")
            ' Issue file not found message as information.
            ts.TraceInformation("File {0} not found.", "test")
            ts.Listeners("console").TraceOutputOptions = ts.Listeners("console").TraceOutputOptions Or TraceOptions.LogicalOperationStack
            ' Issue file not found message as an error event.
            ts.TraceEvent(TraceEventType.Error, 4, "File {0} not found.", "test")
            ' Test the filter on the ConsoleTraceListener.
            ts.Listeners("console").Filter = New SourceFilter("No match")
            ts.TraceData(TraceEventType.Error, 5, "SourceFilter should reject this message for the console trace listener.")
            ts.Listeners("console").Filter = New SourceFilter("TraceTest")
            ts.TraceData(TraceEventType.Error, 6, "SourceFilter should let this message through on the console trace listener.")
            ts.Listeners("console").Filter = Nothing
            ' Use the TraceData method. 
            ts.TraceData(TraceEventType.Warning, 7, New Object())
            ts.TraceData(TraceEventType.Warning, 8, New Object() {"Message 1", "Message 2"})
            ' Activity tests.
            ts.TraceEvent(TraceEventType.Start, 9, "Will not appear until the switch is changed.")
            ts.Switch.Level = SourceLevels.ActivityTracing Or SourceLevels.Critical
            ts.TraceEvent(TraceEventType.Suspend, 10, "Switch includes ActivityTracing, this should appear")
            ts.TraceEvent(TraceEventType.Critical, 11, "Switch includes Critical, this should appear")
            ts.Flush()
            ts.Close()
            Console.WriteLine("Press any key to exit.")
            Console.Read()
        Catch e As Exception
            ' Catch any unexpected exception.
            Console.WriteLine("Unexpected exception: " + e.ToString())
            Console.Read()
        End Try

    End Sub 'Main

    Public Shared Sub DisplayProperties(ByVal ts As TraceSource)
        Console.WriteLine("TraceSource name = " + ts.Name)
        Console.WriteLine("TraceSource switch level = " + ts.Switch.Level.ToString())
        Console.WriteLine("TraceSource switch = " + ts.Switch.DisplayName.ToString())
        Dim switches As SwitchAttribute() = SwitchAttribute.GetAll(GetType(TraceTest).Assembly)
        Dim i As Integer
        For i = 0 To switches.Length - 1
            Console.WriteLine("Switch name = " + switches(i).SwitchName.ToString())
            Console.WriteLine("Switch type = " + switches(i).SwitchType.ToString())
        Next i

#If (ConfigFile) Then
        ' Get the custom attributes for the TraceSource.
        Console.WriteLine("Number of custom trace source attributes = " + ts.Attributes.Count)
        Dim de As DictionaryEntry
        For Each de In ts.Attributes
            Console.WriteLine("Custom trace source attribute = " + de.Key + "  " + de.Value)
        Next de
        ' Get the custom attributes for the trace source switch.
        For Each de In ts.Switch.Attributes
            Console.WriteLine("Custom switch attribute = " + de.Key + "  " + de.Value)
        Next de
#End If
        Console.WriteLine("Number of listeners = " + ts.Listeners.Count.ToString())
        Dim traceListener As TraceListener
        For Each traceListener In ts.Listeners
            Console.Write("TraceListener: " + traceListener.Name + vbTab)
            ' The following output can be used to update the configuration file.
            Console.WriteLine("AssemblyQualifiedName = " + traceListener.GetType().AssemblyQualifiedName)
        Next traceListener

    End Sub 'DisplayProperties
End Class 'TraceTest 

注解

TraceSource 类由应用程序用来生成可与应用程序相关联的跟踪。The TraceSource class is used by applications to produce traces that can be associated with the application. TraceSource 提供了一些跟踪方法,利用这些跟踪方法,你可以方便地跟踪事件,跟踪数据和发出信息跟踪。TraceSource provides tracing methods that allow you to easily trace events, trace data, and issue informational traces. 可以通过配置TraceSource文件设置来控制的跟踪输出。Trace output from TraceSource can be controlled by configuration file settings. 配置文件位于具有应用程序可执行文件的文件夹中,并具有添加了 .config 文件扩展名的应用程序的名称。The configuration file is located in the folder with the application executable and has the name of the application with the .config file name extension added. 例如,"TraceSourceSample" 的配置文件的名称为 "TraceSourceSample"。配置文件可用于确定要将跟踪信息发送到的位置以及要跟踪的活动级别。For example, the name of the configuration file for TraceSourceSample.exe is TraceSourceSample.exe.config. The configuration file can be used to determine where the trace information is to be sent and what levels of activity are to be traced. 下面的示例显示示例应用程序配置文件的内容。The following example shows the contents of a sample application configuration file.

<configuration>  
  <system.diagnostics>  
    <sources>  
      <source name="TraceTest" switchName="SourceSwitch"   
        switchType="System.Diagnostics.SourceSwitch" >  
        <listeners>  
          <add name="console" />  
          <remove name ="Default" />  
        </listeners>  
      </source>  
    </sources>  
    <switches>  
      <!-- You can set the level at which tracing is to occur -->  
      <add name="SourceSwitch" value="Warning" />  
        <!-- You can turn tracing off -->  
        <!--add name="SourceSwitch" value="Off" -->  
    </switches>  
    <sharedListeners>  
      <add name="console"   
        type="System.Diagnostics.ConsoleTraceListener"   
        initializeData="false"/>  
    </sharedListeners>  
    <trace autoflush="true" indentsize="4">  
      <listeners>  
        <add name="console" />  
      </listeners>  
    </trace>  
  </system.diagnostics>  
</configuration>  

TraceSource类由源的名称标识,通常为应用程序的名称。The TraceSource class is identified by the name of a source, typically the name of the application. 来自特定组件的跟踪消息可以由特定跟踪源启动,从而可以轻松地识别来自该组件的所有消息。The trace messages coming from a particular component can be initiated by a particular trace source, allowing all messages coming from that component to be easily identified.

TraceSource定义跟踪方法,但实际上并不提供用于生成和存储跟踪数据的任何特定机制。TraceSource defines tracing methods but does not actually provide any specific mechanism for generating and storing tracing data. 跟踪数据由跟踪侦听器生成,跟踪侦听器是可以通过跟踪源加载的插件。The tracing data is produced by trace listeners, which are plug-ins that can be loaded by trace sources.

备注

不应在终止过程中调用跟踪方法。You should not call the tracing methods during finalization. 这样做可能导致ObjectDisposedException引发。Doing so can result in an ObjectDisposedException being thrown.

您可以通过在TraceListener TraceSource.Listeners存储在属性中的集合中添加或删除实例来自定义跟踪输出的目标。You can customize the tracing output's target by adding or removing TraceListener instances to or from the collection stored in the TraceSource.Listeners property. 默认情况下,使用DefaultTraceListener类的实例生成跟踪输出。By default, trace output is produced using an instance of the DefaultTraceListener class. 前面的配置文件示例演示如何删除DefaultTraceListenerConsoleTraceListener添加以生成跟踪源的跟踪输出。The preceding configuration file example demonstrates removing the DefaultTraceListener and adding a ConsoleTraceListener to produce the trace output for the trace source. 有关详细信息,请 <参阅>侦听器 <sharedListeners>For more information, see <listeners> and <sharedListeners>.

备注

如果跟踪侦听器使用的资源Listeners不可用,则在跟踪时将跟踪侦听器添加到集合可能导致引发异常。Adding a trace listener to the Listeners collection can cause an exception to be thrown while tracing, if a resource used by the trace listener is not available. 条件和引发的异常依赖于跟踪侦听器,在本主题中无法枚举。The conditions and the exception thrown depend on the trace listener and cannot be enumerated in this topic. TraceSource块中try 调用方法以catch检测和处理跟踪侦听器中的任何异常可能会很有用。 /It may be useful to place calls to the TraceSource methods in try/catch blocks to detect and handle any exceptions from trace listeners.

SourceSwitch类提供动态控制跟踪输出的方法。The SourceSwitch class provides the means to dynamically control the tracing output. 前面的配置文件示例演示了如何从跟踪源关闭跟踪并控制跟踪发生的级别。The preceding configuration file example shows how you can turn off tracing from a trace source and control the level at which tracing occurs. 您可以修改源开关的值,而无需重新编译应用程序。You can modify the value of the source switch without recompiling your application. 有关使用配置文件设置开关的信息,请参阅Switch如何:创建、初始化和配置跟踪开关For information on using the configuration file to set a switch, see Switch and How to: Create, Initialize and Configure Trace Switches.

备注

如果在应用程序执行时修改配置文件,则必须停止并重新启动应用程序,或者Refresh必须先调用方法,然后新设置才会生效。If you modify a configuration file while an application is executing, the application must be stopped and restarted or the Refresh method must be called before the new settings take effect.

TraceEventType枚举用于定义跟踪消息的事件类型。The TraceEventType enumeration is used to define the event type of the trace message. 跟踪筛选器使用TraceEventType来确定跟踪侦听器是否应生成跟踪消息。Trace filters use the TraceEventType to determine if a trace listener should produce the trace message.

跟踪侦听器可以选择通过跟踪筛选器额外进行筛选。The trace listeners can optionally have an additional layer of filtering through a trace filter. 如果跟踪侦听器具有关联的筛选器,则侦听器会对ShouldTrace该筛选器调用方法,以确定是否生成跟踪信息。If a trace listener has an associated filter, the listener calls the ShouldTrace method on that filter to determine whether or not to produce the trace information.

跟踪侦听器使用Trace类属性IndentIndentSizeAutoFlush的值来设置跟踪输出的格式。The trace listeners use the values of the Trace class properties Indent, IndentSize, and AutoFlush to format trace output. 您可以使用配置文件特性来设置IndentIndentSizeAutoFlush属性。You can use configuration file attributes to set the Indent, IndentSize, and AutoFlush properties. 下面的示例将AutoFlush属性设置为false ,并IndentSize将属性设置为3。The following example sets the AutoFlush property to false and the IndentSize property to 3.

<configuration>  
  <system.diagnostics>  
    <trace autoflush="false" indentsize="3" />  
  </system.diagnostics>  
</configuration>  

构造函数

TraceSource(String) TraceSource(String) TraceSource(String) TraceSource(String)

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

TraceSource(String, SourceLevels) TraceSource(String, SourceLevels) TraceSource(String, SourceLevels) 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.

属性

Attributes Attributes Attributes Attributes

获取在应用程序配置文件中定义的自定义开关特性。Gets the custom switch attributes defined in the application configuration file.

Listeners Listeners Listeners Listeners

获取跟踪源的跟踪侦听器集合。Gets the collection of trace listeners for the trace source.

Name Name Name Name

获取跟踪源的名称。Gets the name of the trace source.

Switch Switch Switch Switch

获取或设置源开关的值。Gets or sets the source switch value.

方法

Close() Close() Close() Close()

关闭跟踪侦听器集合中的所有跟踪侦听器。Closes all the trace listeners in the trace listener collection.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
Flush() Flush() Flush() Flush()

刷新跟踪侦听器集合中的所有跟踪侦听器。Flushes all the trace listeners in the trace listener collection.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes() GetSupportedAttributes()

获取跟踪源所支持的自定义特性。Gets the custom attributes supported by the trace source.

GetType() GetType() GetType() GetType()

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

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
TraceData(TraceEventType, Int32, Object) TraceData(TraceEventType, Int32, Object) TraceData(TraceEventType, Int32, Object) TraceData(TraceEventType, Int32, Object)

使用指定的事件类型、事件标识符和跟踪数据,将跟踪数据写入 Listeners 集合中的跟踪侦听器中。Writes trace data to the trace listeners in the Listeners collection using the specified event type, event identifier, and trace data.

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

使用指定的事件类型、事件标识符和跟踪数据数组,将跟踪数据写入 Listeners 集合中的跟踪侦听器中。Writes trace data to the trace listeners in the Listeners collection using the specified event type, event identifier, and trace data array.

TraceEvent(TraceEventType, Int32) TraceEvent(TraceEventType, Int32) TraceEvent(TraceEventType, Int32) TraceEvent(TraceEventType, Int32)

使用指定的事件类型和事件标识符,将跟踪事件消息写入 Listeners 集合中的跟踪侦听器中。Writes a trace event message to the trace listeners in the Listeners collection using the specified event type and event identifier.

TraceEvent(TraceEventType, Int32, String) TraceEvent(TraceEventType, Int32, String) TraceEvent(TraceEventType, Int32, String) TraceEvent(TraceEventType, Int32, String)

使用指定的事件类型、事件标识符和消息,将跟踪事件消息写入 Listeners 集合中的跟踪侦听器中。Writes a trace event message to the trace listeners in the Listeners collection using the specified event type, event identifier, and message.

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

使用指定的事件类型、事件标识符以及参数数组和格式,将跟踪事件写入 Listeners 集合中的跟踪侦听器中。Writes a trace event to the trace listeners in the Listeners collection using the specified event type, event identifier, and argument array and format.

TraceInformation(String) TraceInformation(String) TraceInformation(String) TraceInformation(String)

使用指定消息,将信息性消息写入 Listeners 集合中的跟踪侦听器中。Writes an informational message to the trace listeners in the Listeners collection using the specified message.

TraceInformation(String, Object[]) TraceInformation(String, Object[]) TraceInformation(String, Object[]) TraceInformation(String, Object[])

使用指定的对象数组和格式化信息,将信息性消息写入 Listeners 集合中的跟踪侦听器中。Writes an informational message to the trace listeners in the Listeners collection using the specified object array and formatting information.

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

使用指定的数字标识符、消息和相关活动标识符,将跟踪传输消息写入 Listeners 集合的跟踪侦听器中。Writes a trace transfer message to the trace listeners in the Listeners collection using the specified numeric identifier, message, and related activity identifier.

适用于

线程安全性

此类型是线程安全的。This type is thread safe.

另请参阅