Using the Debug and Trace Classes

The useful methods and properties are shared. The overloaded WriteLine and Write are used to write debug or trace output. The overloaded WriteLineIf and WriteIf write output if the condition in their first argument is true.

Debug.WriteLine( _
   "This was compiled with a DEBUG directive!")
Trace.WriteLine( _
   "This was compiled with a TRACE directive!")
...
Debug.WriteLineIf(DebugBooleanSwitch.Enabled, _
   "Debug Boolean Switch enabled at startup.")
Debug.WriteLineIf(Not DebugBooleanSwitch.Enabled, _
   "Debug Boolean Switch disabled at startup.")

Output is indented with the Indent and Unindent methods. The indentation size is controlled with the IndentSize property.

Trace.Indent()
...
Trace.IndentSize = 10

You can ...

Get Application Development Using Visual Basic® and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.