Debug.Write 方法

定义

将有关调试的信息写入 Listeners 集合中的跟踪侦听器。

重载

Write(String, String)

将类别名称和消息写入 Listeners 集合中的跟踪侦听器。

Write(Object, String)

将类别名称和对象的 ToString() 方法的值写入 Listeners 集合中的跟踪侦听器。

Write(String)

将消息写入 Listeners 集合中的跟踪侦听器。

Write(Object)

将对象的 ToString() 方法的值写入 Listeners 集合中的跟踪侦听器。

Write(String, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

将类别名称和消息写入 Listeners 集合中的跟踪侦听器。

public:
 static void Write(System::String ^ message, System::String ^ category);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (string message, string category);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (string? message, string? category);
[<System.Diagnostics.Conditional("DEBUG")>]
static member Write : string * string -> unit
Public Shared Sub Write (message As String, category As String)

参数

message
String

要写入的消息。

category
String

用于组织输出的类别名称。

属性

示例

以下示例创建一个名为 generalSwitchTraceSwitch。 此开关在代码示例之外设置。

如果开关设置为 TraceLevelError 或更高版本,则本示例将第一条错误消息输出到 Listeners。 有关向 Listeners 集合添加侦听器的信息,请参阅 TraceListenerCollection 类。

然后,如果 TraceLevel 设置为 Verbose,则该示例将输出第二条错误消息,该错误消息与第一条消息位于同一行。 行终止符紧跟第二条消息。

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( myObject, category );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::Write( " Object is not valid for this category." );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject, string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write(myObject, category);

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(" Object is not valid for this category.");
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write(myObject, category)
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(" Object is not valid for this category.")
    End If
End Sub

注解

默认情况下,输出将写入 DefaultTraceListener实例。

使用 category 参数对输出消息进行分组。

此方法调用跟踪侦听器的 Write 方法。

另请参阅

适用于

Write(Object, String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

将类别名称和对象的 ToString() 方法的值写入 Listeners 集合中的跟踪侦听器。

public:
 static void Write(System::Object ^ value, System::String ^ category);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (object value, string category);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (object? value, string? category);
[<System.Diagnostics.Conditional("DEBUG")>]
static member Write : obj * string -> unit
Public Shared Sub Write (value As Object, category As String)

参数

value
Object

将名称发送到 Listeners的对象。

category
String

用于组织输出的类别名称。

属性

示例

以下示例创建一个名为 generalSwitchTraceSwitch。 此开关在代码示例之外设置。

如果开关设置为 TraceLevelError 或更高版本,则本示例将第一条错误消息输出到 Listeners。 有关向 Listeners 集合添加侦听器的信息,请参阅 TraceListenerCollection 类。

然后,如果 TraceLevel 设置为 Verbose,则该示例将输出第二条错误消息,该错误消息与第一条消息位于同一行。 行终止符紧跟第二条消息。

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( myObject, category );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::Write( " Object is not valid for this category." );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject, string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write(myObject, category);

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(" Object is not valid for this category.");
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write(myObject, category)
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(" Object is not valid for this category.")
    End If
End Sub

注解

默认情况下,输出将写入 DefaultTraceListener实例。

使用 category 参数对输出消息进行分组。

此方法调用跟踪侦听器的 Write 方法。

另请参阅

适用于

Write(String)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

将消息写入 Listeners 集合中的跟踪侦听器。

public:
 static void Write(System::String ^ message);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (string message);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (string? message);
[<System.Diagnostics.Conditional("DEBUG")>]
static member Write : string -> unit
Public Shared Sub Write (message As String)

参数

message
String

要写入的消息。

属性

示例

以下示例创建一个名为 generalSwitchTraceSwitch。 此开关在代码示例之外设置。

如果开关设置为 TraceLevelError 或更高版本,则本示例将第一条错误消息输出到 Listeners。 有关向 Listeners 集合添加侦听器的信息,请参阅 TraceListenerCollection 类。

然后,如果 TraceLevel 设置为 Verbose,则该示例将输出第二条错误消息,该错误消息与第一条消息位于同一行。 行终止符紧跟第二条消息。

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( myObject, category );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::Write( " Object is not valid for this category." );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject, string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write(myObject, category);

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(" Object is not valid for this category.");
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write(myObject, category)
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(" Object is not valid for this category.")
    End If
End Sub

注解

默认情况下,输出将写入 DefaultTraceListener实例。

此方法调用跟踪侦听器的 Write 方法。

另请参阅

适用于

Write(Object)

Source:
Debug.cs
Source:
Debug.cs
Source:
Debug.cs

将对象的 ToString() 方法的值写入 Listeners 集合中的跟踪侦听器。

public:
 static void Write(System::Object ^ value);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (object value);
[System.Diagnostics.Conditional("DEBUG")]
public static void Write (object? value);
[<System.Diagnostics.Conditional("DEBUG")>]
static member Write : obj -> unit
Public Shared Sub Write (value As Object)

参数

value
Object

将名称发送到 Listeners的对象。

属性

示例

以下示例创建一个名为 generalSwitchTraceSwitch。 此开关在代码示例之外设置。

如果开关设置为 TraceLevelError 或更高版本,则本示例将第一条错误消息输出到 Listeners。 有关向 Listeners 集合添加侦听器的信息,请参阅 TraceListenerCollection 类。

然后,如果 TraceLevel 设置为 Verbose,则该示例将输出第二条错误消息,该错误消息与第一条消息位于同一行。 行终止符紧跟第二条消息。

   // Class-level declaration.
   // Create a TraceSwitch.
   static TraceSwitch^ generalSwitch = 
      gcnew TraceSwitch( "General","Entire Application" );

public:
   static void MyErrorMethod( Object^ myObject, String^ category )
   {
      // Write the message if the TraceSwitch level is set to Error or higher.
      if ( generalSwitch->TraceError )
      {
         #if defined(DEBUG)
         Debug::Write( myObject, category );
         #endif
      }
      // Write a second message if the TraceSwitch level is set to Verbose.
      if ( generalSwitch->TraceVerbose )
      {
         #if defined(DEBUG)
         Debug::Write( " Object is not valid for this category." );
         #endif
      }
   }
// Class-level declaration.
// Create a TraceSwitch.
static TraceSwitch generalSwitch = new TraceSwitch("General", "Entire Application");

static public void MyErrorMethod(Object myObject, string category)
{
    // Write the message if the TraceSwitch level is set to Error or higher.
    if (generalSwitch.TraceError)
        Debug.Write(myObject, category);

    // Write a second message if the TraceSwitch level is set to Verbose.
    if (generalSwitch.TraceVerbose)
        Debug.WriteLine(" Object is not valid for this category.");
}
' Class-level declaration.
' Create a TraceSwitch.
Private Shared generalSwitch As New TraceSwitch("General", "Entire Application")


Public Shared Sub MyErrorMethod(myObject As Object, category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write(myObject, category)
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(" Object is not valid for this category.")
    End If
End Sub

注解

默认情况下,输出将写入 DefaultTraceListener实例。

此方法调用跟踪侦听器的 Write 方法。

另请参阅

适用于