Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Debug.Write Method

Writes information about the debug to the trace listeners in the Listeners collection.

Overload List

Writes the value of the object's ToString method to the trace listeners in the Listeners collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Object)
[C#] public static void Write(object);
[C++] public: static void Write(Object*);
[JScript] public static function Write(Object);

Writes a message to the trace listeners in the Listeners collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String)
[C#] public static void Write(string);
[C++] public: static void Write(String*);
[JScript] public static function Write(String);

Writes a category name and the value of the object's ToString method to the trace listeners in the Listeners collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(Object, String)
[C#] public static void Write(object, string);
[C++] public: static void Write(Object*, String*);
[JScript] public static function Write(Object, String);

Writes a category name and message to the trace listeners in the Listeners collection.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub Write(String, String)
[C#] public static void Write(string, string);
[C++] public: static void Write(String*, String*);
[JScript] public static function Write(String, String);

Example

The following example creates a TraceSwitch named generalSwitch. This switch is set outside of the code sample.

If the switch is set to the TraceLevel Error or higher, the example outputs the first error message to the Listeners. For information on adding a listener to the Listeners collection, see the TraceListenerCollection class.

Then, if the TraceLevel is set to Verbose, the example outputs the second error message on the same line as the first message. A line terminator follows the second message.

[Visual Basic] 
' 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 'MyErrorMethod 

[C#] 
// 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.");
 }


[C++] 
// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch* generalSwitch = new TraceSwitch(S"General", S"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)
       Debug::Write(myObject, category);
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch->TraceVerbose)
       Debug::WriteLine(S" Object is not valid for this category.");
 }


[JScript] 
// Class level declaration.
 // Create a TraceSwitch.
 static var generalSwitch : TraceSwitch = new TraceSwitch("General", "Entire Application");
 
 static public function MyErrorMethod(myObject : Object, category : String) {
    // 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.");
 }

See Also

Debug Class | Debug Members | System.Diagnostics Namespace

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft