NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Debug Class

Provides a set of properties and methods for debugging code.

Object
   Debug

[Visual Basic]
Public Class Debug
[C#]
public class Debug
[C++]
public __gc class Debug
[JScript]
public class Debug

Remarks

By using methods in the Debug class to print debugging information and check your logic with assertions, you can make your code more robust without impacting your shipping product's performance and code size. By default, Debug is off in retail builds.

The BooleanSwitch and TraceSwitch classes provide a means to control the tracing output dynamically. The values of these switches can be modified outside the compiled application.

You can customize the tracing output's target by adding TraceListener instances to or removing instances from the Listeners collection. By default, trace output is emitted using the DefaultTraceListener class.

The Debug class provides properties to get or set the level of Indent, the IndentSize and whether to AutoFlush after each write.

This class also provides methods to display an Assert dialog box, and to set an assertion that will always Fail. This class provides write methods in the following variations: Write, WriteLine, WriteIf and WriteLineIf.

Use Trace to instrument retail builds.

For more information, see <DebugTopicTBD>.

Requirements

Namespace: System.Diagnostics

Assembly: System.dll

Example [C#]

The following example creates three switches to control the debugging output for the Customer class.

[C#]

Class Customer{
   // trace each method flow
   static BooleanSwitch debugMethods("DebugMethods","Debug logic flow"); 
   // trace method parameters 
   static BooleanSwitch debugParams("DebugParams","Debug parameter values");   
   // trace return values
   static BooleanSwitch debugResults("DebugResults","Debug calculations"); 

   string Name(string last, string first){
      Debug.WriteLineIf(debugMethods.Enabled, "Name called");
      Debug.WriteLineIf(debugParams.Enabled, "Params: " + last + ", " + first);
      
      string fullName = first + " " + last;
      
      Debug.WriteLineIf(debugMethods.Enabled, "Name terminates");
      Debug.WriteLineIf(debugResults.Enabled, "Result: " + fullName); 
      return fullName;
   }
}

If the debugMethods and debugResults are set to true, and debugParams is set to false, the output for a call to Name("Smith", "John") would be:

Name called

Name terminates

Result: John Smith

See Also

Debug Members | System.Diagnostics Namespace | Trace | BooleanSwitch | TraceSwitch | TraceListener | DefaultTraceListener | ConditionalAttribute