This documentation is archived and is not being maintained.

Debug.WriteLine Method (Object)

.NET Framework 1.1

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

[Visual Basic]
<Conditional("DEBUG")>
Overloads Public Shared Sub WriteLine( _
   ByVal value As Object _
)
[C#]
[Conditional("DEBUG")]
public static void WriteLine(
 object value
);
[C++]
[Conditional("DEBUG")]
public: static void WriteLine(
 Object* value
);
[JScript]
public
   Conditional("DEBUG")
static function WriteLine(
 value : Object
);

Parameters

value
An object whose name is sent to the Listeners.

Remarks

By default, the output is written to an instance of DefaultTraceListener.

This method calls the WriteLine method of the trace listener.

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 name of the object 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)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("Invalid object. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine(myObject)
    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) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch.TraceError)
       Debug.Write("Invalid object. ");
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch.TraceVerbose)
       Debug.WriteLine(myObject);
 }


[C++] 
// Class-level declaration.
 // Create a TraceSwitch.
 static TraceSwitch* generalSwitch = new TraceSwitch(S"General", S"Entire Application");
 
public:
 static void MyErrorMethod(Object* myObject) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch->TraceError)
       Debug::Write(S"Invalid object. ");
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch->TraceVerbose)
       Debug::WriteLine(myObject);
 }


[JScript] 
// Class level declaration.
 // Create a TraceSwitch.
 static var generalSwitch : TraceSwitch = new TraceSwitch("General", "Entire Application");
 
 static public function MyErrorMethod(myObject : Object) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch.TraceError)
       Debug.Write("Invalid object. ");
 
    //Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch.TraceVerbose)
       Debug.WriteLine(myObject);
 }

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

Debug Class | Debug Members | System.Diagnostics Namespace | Debug.WriteLine Overload List | Debug | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute | ConditionalAttribute

Show: