Name
Debug
Synopsis
This class provides methods that allow you
to print debugging information and use assertions.
The Listeners
collection contains a set of
listeners that are responsible for reporting debugging operations
through the user interface or trace log. That collection
initially includes an instance of DefaultTraceListener
.
Add a TraceListener
using the
Add()
method of the Listeners
property.
Use Close()
or Flush()
to close or flush
all listeners that write
output to a file, such as the TextWriterTraceListener
.
Set AutoFlush
to true
to automatically flush each listener
after a write operation.
Assert()
specifies a condition and an optional
error message to display if the condition is
false
. If the
DefaultTraceListener
’s AssertUiEnabled
property is true
, the error message is displayed
as a dialog, and the user has the opportunity to abort the program,
retry (test the assertion again), or ignore the failed assertion.
Otherwise, the error message is written to
DefaultTraceListener.LogFileName
.
Fail()
acts like an assertion in which the condition is
always false
.
Indent()
and Unindent()
allow you
to set the level of indentation when you call Debug.WriteLine()
.
Use IndentSize
to set the number of spaces
corresponding to indented text. Write()
and
WriteLine()
send output to each
TraceListener
in the
Listeners
collection, and
WriteIf()
and WriteLineIf()
allow you to conditionally output debug information.
You can use the application configuration file to add or remove trace ...
Get C# in a Nutshell 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.