Debug Class
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Provides a set of methods and properties that help debug your code. This class cannot be inherited.
Assembly: System (in System.dll)
The Debug type exposes the following members.
| Name | Description | |
|---|---|---|
![]() ![]() | Assert(Boolean) | Checks for a condition and outputs the call stack if the condition is false. |
![]() ![]() | Assert(Boolean, String) | Checks for a condition and displays a specified message if the condition is false. |
![]() ![]() | Assert(Boolean, String, String) | Checks for a condition and displays two specified messages if the condition is false. |
![]() ![]() | Assert(Boolean, String, String, array<Object>) | Checks for a condition and outputs the message and the call stack if the condition is false. |
![]() ![]() | WriteLine(Object) | Writes the value of a specified object's ToString method to the debugger by using the OutputDebugString function. |
![]() ![]() | WriteLine(String) | Writes a specified message followed by a line terminator to the debugger by using the OutputDebugString function. |
![]() ![]() | WriteLine(String, array<Object>) | Writes a formatted string followed by a line terminator to the debugger by using the OutputDebugString function. |
![]() ![]() | WriteLineIf | Writes a specified message followed by a line terminator to the debugger by using OutputDebugString function if a condition is true. |
If you use methods in the Debug class to display debugging information and check your logic with assertions, you can make your code more robust without affecting the performance and code size of your shipping product.
This class provides methods for displaying an Assert dialog box, and for emitting an assertion that will always fail. This class provides write methods in the following variations: WriteLine(Object), WriteLine(String), and WriteLine(String, array<Object>).
Note: |
|---|
The debugging methods in the Debug class behave differently in Windows Phone applications than they do in desktop applications. There is no Listeners collection to specify the destination for debug output. The debugging information is sent to the OutputDebugString function and to the debugger, if one is attached. The Visual Studio debugger displays the information in the Output window. If a debugger is not attached, the output from OutputDebugString can be viewed by using a debug viewer. |
To define the "DEBUG" conditional compilation symbol in C#, add the /d:DEBUG option to the compiler command line when you compile your code or add #define DEBUG to the top of your file. In Visual Basic, add the /d:DEBUG=True option to the compiler command line or add #Const DEBUG=True to the file.
In Visual Studio projects, by default, the "DEBUG" conditional compilation symbol is defined for debug builds, and the "TRACE" symbol is defined for both debug and release builds. For information on how to disable this behavior, see the Visual Studio documentation.
| Topic | Location |
|---|---|
| How to: Create and Initialize Trace Listeners | .NET Framework: Debugging |
| How to: Compile Conditionally with Trace and Debug | .NET Framework: Debugging |
| How to: Configure Trace Switches | .NET Framework: Debugging |
| How to: Trace Code in an Application | .NET Framework: Debugging |
| How to: Add Trace Statements to Application Code | .NET Framework: Debugging |
| How to: Create and Initialize Trace Listeners | .NET Framework: Debugging |
| How to: Compile Conditionally with Trace and Debug | .NET Framework: Debugging |
| How to: Configure Trace Switches | .NET Framework: Debugging |
| How to: Trace Code in an Application | .NET Framework: Debugging |
| How to: Add Trace Statements to Application Code | .NET Framework: Debugging |


Note: