Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

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 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# in a Nutshell

C# in a Nutshell

Ben Albahari, Ted Neward, Peter Drayton
C# 7.0 in a Nutshell

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata