Outputting Trace and Debug Information
One useful way to gather debugging information when a template is not behaving as you expect is to use the methods of the .NET System.Diagnostics.Trace and System.Diagnostics.Debug objects. These objects let your code interact with the Debug pane of the Output window. The two objects have exactly the same members; the only difference between the two is that the System.Diagnostics.Trace object is active at all times, while the System.Diagnostics.Debug object is only active when you compile your code in debug mode.
This table summarizes some of the useful members of the Trace and Debug objects:
Member | Type | Description |
Assert | Method | Checks for a condition, and displays a message if the condition is false. |
Fail | Method | Displays an error message |
Indent | Method | Increases the current IndentLevel by one. |
IndentLevel | Property | Specifies the indent level. |
IndentSize | Property | Specifies the number of spaces in an indent. |
Unindent | Method | Decreases the current IndentLevel by one. |
Write | Method | Writes the given information |
WriteIf | Method | Writes the given information only if a condition is true |
WriteLine | Method | Same as Write but appends a new line character after the information. |
WriteLineIf | Method | Same as WriteIf but appends a new line character after the information. |