Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0226 Debug and Trace Classes

All methods of the Debug class are defined with [Conditional("DEBUG")]. All methods of the Trace class are defined with [Conditional("TRACE")]. All calls from Debug class are eliminated by the compiler unless you define DEBUG symbol. All calls from Trace class are eliminated by the compiler unless you define TRACE symbol. By default, Visual Studio defines both DEBUG and TRACE symbols in a debug configuration. By default, Visual Studio defines TRACE symbol in the release configuration. Both the Debug and Trace classes provide Write, WriteLine, and WriteIf methods. #define TESTMODE using System; using System.Diagnostics; class Program { static void Main() { Debug.Write("information"); Debug.WriteLine(3 * 3); Debug.WriteIf(2 > 1, "your message"); Trace.Write("information"); Trace.WriteLine(3 * 3); Trace.WriteIf(2 > 1, "your message"); } }