--- title: "Debug Class (C++/CLI) | Microsoft Docs" ms.custom: "" ms.date: "11/04/2016" ms.reviewer: "" ms.suite: "" ms.technology: - "cpp-windows" ms.tgt_pltfrm: "" ms.topic: "article" dev_langs: - "C++" helpviewer_keywords: - "Trace class, Visual C++" - ".NET Framework [C++], Debug class" - "Debug class" ms.assetid: 076bd528-1b6f-4e8a-a372-eb5849cf969a caps.latest.revision: 5 author: "mikeblome" ms.author: "mblome" manager: "ghogen" translation.priority.ht: - "cs-cz" - "de-de" - "es-es" - "fr-fr" - "it-it" - "ja-jp" - "ko-kr" - "pl-pl" - "pt-br" - "ru-ru" - "tr-tr" - "zh-cn" - "zh-tw" --- # Debug Class (C++/CLI) When using in a Visual C++ application, the behavior does not change between a debug and a release build. ## Remarks The behavior for is identical to the behavior for the Debug class, but is dependent on the symbol TRACE being defined. This means that you must `#ifdef` any Trace-related code to prevent debug behavior in a release build. ## Example ### Description The following sample always executes the output statements, regardless of whether you compile with **/DDEBUG** or **/DTRACE**. ### Code ``` // mcpp_debug_class.cpp // compile with: /clr #using using namespace System::Diagnostics; using namespace System; int main() { Trace::Listeners->Add( gcnew TextWriterTraceListener( Console::Out ) ); Trace::AutoFlush = true; Trace::Indent(); Trace::WriteLine( "Entering Main" ); Console::WriteLine( "Hello World." ); Trace::WriteLine( "Exiting Main" ); Trace::Unindent(); Debug::WriteLine("test"); } ``` ### Output ``` Entering Main Hello World. Exiting Main test ``` ## Example ### Description To get the expected behavior (that is, no "test" output printed for a release build), you must use the `#ifdef` and `#endif` directives. The previous code sample is modified below to demonstrate this fix: ### Code ``` // mcpp_debug_class2.cpp // compile with: /clr #using using namespace System::Diagnostics; using namespace System; int main() { Trace::Listeners->Add( gcnew TextWriterTraceListener( Console::Out ) ); Trace::AutoFlush = true; Trace::Indent(); #ifdef TRACE // checks for a debug build Trace::WriteLine( "Entering Main" ); Console::WriteLine( "Hello World." ); Trace::WriteLine( "Exiting Main" ); #endif Trace::Unindent(); #ifdef DEBUG // checks for a debug build Debug::WriteLine("test"); #endif //ends the conditional block } ``` ## See Also [.NET Programming with C++/CLI (Visual C++)](../dotnet/dotnet-programming-with-cpp-cli-visual-cpp.md)