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
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

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

属性

示例

以下示例创建一个 TraceSwitch 命名的 generalSwitch。 此开关在代码示例之外设置。

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

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

// 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
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

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

属性

示例

以下示例创建一个 TraceSwitch 命名的 generalSwitch。 此开关在代码示例之外设置。

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

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

// 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
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

要写入的消息。

属性

示例

以下示例创建一个 TraceSwitch 命名的 generalSwitch。 此开关在代码示例之外设置。

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

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

// 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
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

属性

示例

以下示例创建一个 TraceSwitch 命名的 generalSwitch。 此开关在代码示例之外设置。

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

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

// 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 跟踪侦听器的方法。

另请参阅

适用于