Export (0) Print
Expand All

Debug.WriteLineIf Method

Writes information about the debug to the trace listeners in the Listeners collection if a condition is true.

Overload List

Writes the value of the object's ToString method to the trace listeners in the Listeners collection if a condition is true.

Supported by the .NET Compact Framework.

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

Writes a message to the trace listeners in the Listeners collection if a condition is true.

Supported by the .NET Compact Framework.

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

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

Supported by the .NET Compact Framework.

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

Writes a category name and message to the trace listeners in the Listeners collection if a condition is true.

Supported by the .NET Compact Framework.

[Visual Basic] Overloads Public Shared Sub WriteLineIf(Boolean, String, String)
[C#] public static void WriteLineIf(bool, string, string);
[C++] public: static void WriteLineIf(bool, String*, String*);
[JScript] public static function WriteLineIf(Boolean, 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 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.
    Debug.WriteIf(generalSwitch.TraceError, "My error message. ")
    
    ' Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteLineIf(generalSwitch.TraceVerbose, "My second error message.", category)
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.
    Debug.WriteIf(generalSwitch.TraceError, "My error message. ");
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteLineIf(generalSwitch.TraceVerbose, "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.
    Debug::WriteIf(generalSwitch->TraceError, S"My error message. ");
 
    // Write a second message if the TraceSwitch level is set to Verbose.
    Debug::WriteLineIf(generalSwitch->TraceVerbose, 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.
    Debug.WriteIf(generalSwitch.TraceError, "My error message. ");
 
    //Write a second message if the TraceSwitch level is set to Verbose.
    Debug.WriteLineIf(generalSwitch.TraceVerbose, "My second error message.", category);
 }

See Also

Debug Class | Debug Members | System.Diagnostics Namespace

Show:
© 2014 Microsoft