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

Trace

Synopsis

This class supplies static methods and properties to provide tracing ability. The calls to the Trace methods and properties are executed only if tracing is enabled. (See the introduction to this chapter for instructions on enabling tracing.)

The static properties allow you to adjust the settings that are used when you call the methods. You can specify that output be indented a certain amount with IndentLevel or increase or decrease the IndentLevel by one using Indent( ) and Unindent( ). You can also adjust the number of spaces each indent level adds using IndentSize. AutoFlush makes sure that after each use of a Trace method, the Listeners are flushed.

Write( ) and WriteLine( ) simply write to each TraceListener in the Listeners collection (by default, this collection includes an instance of DefaultTraceListener). WriteIf( ) and WriteLineIf( ) do the same, but only if the specified condition evaluates to true. Assert( ) emits an error message if a condition evaluates to false, and Fail( ) always emits an error message.

One possible point of confusion is that Listeners is read-only. This means that you may not point Listeners to a different collection. You can, however, add new TraceListener objects to the TraceListenerCollection with the TraceListenerCollection.Add( ) method.

You can use the application configuration file to configure this class. Under the <system.diagnostics> element, add a <trace> element. You can set attributes for this element that correspond ...

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

Joe Mayo

Publisher Resources

ISBN: 0596005261Catalog PageErrata