Export (0) Print
Expand All

Debug.WriteLine Method (String, String)

.NET Framework 1.1

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

[Visual Basic]
<Conditional("DEBUG")>
Overloads Public Shared Sub WriteLine( _
   ByVal message As String, _
   ByVal category As String _
)
[C#]
[Conditional("DEBUG")]
public static void WriteLine(
 string message,
 string category
);
[C++]
[Conditional("DEBUG")]
public: static void WriteLine(
 String* message,
 String* category
);
[JScript]
public
   Conditional("DEBUG")
static function WriteLine(
 message : String,
 category : String
);

Parameters

message
A message to write.
category
A category name used to organize the output.

Remarks

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

The category parameter can be used to group output messages.

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 second error message and the category 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(category As String)
    ' Write the message if the TraceSwitch level is set to Error or higher.
    If generalSwitch.TraceError Then
        Debug.Write("My error message. ")
    End If 
    ' Write a second message if the TraceSwitch level is set to Verbose.
    If generalSwitch.TraceVerbose Then
        Debug.WriteLine("My second error message.", 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(String category) {
    // Write the message if the TraceSwitch level is set to Error or higher.
    if(generalSwitch.TraceError)
       Debug.Write("My error message. ");
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    if(generalSwitch.TraceVerbose)
       Debug.WriteLine("My second error message.", category);
 }


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


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

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

Show:
© 2015 Microsoft