Skip to Main Content
C# in a Nutshell
book

C# in a Nutshell

by Ben Albahari, Ted Neward, Peter Drayton
March 2002
Intermediate to advanced content levelIntermediate to advanced
864 pages
31h 8m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# 8.0 in a Nutshell

C# 8.0 in a Nutshell

Joseph Albahari, Eric Johannsen
C# 10 in a Nutshell

C# 10 in a Nutshell

Joseph Albahari
C# in a Nutshell, Second Edition

C# in a Nutshell, Second Edition

Peter Drayton, Ben Albahari, Ted Neward
Code like a Pro in C#

Code like a Pro in C#

Jort Rodenburg

Publisher Resources

ISBN: 0596001819Catalog PageErrata