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

Chapter 19. Diagnostics

Even good applications sometimes have bad things happen to them. When things go wrong, it is important to detect this as soon as possible, and to gather information to aid in diagnosing the source of the problem. On the developer’s desktop, the tools for doing this include debuggers and profilers. However, once the application leaves the desktop, these tools are generally no longer available. Consequently, it becomes the application’s responsibility to perform this detection and information-gathering role.

Because providing integrated error handling and reporting is such a common need among applications, the .NET Framework provides a diverse set of facilities to monitor application behavior, detect runtime errors, inspect the application environment, report application status and integrate with debugging tools if available.

This chapter introduces the debugging and diagnostics support in the .NET Framework, which is primarily contained in the System.Diagnostics namespace. Unless otherwise stated, the types mentioned in this chapter all exist in either the System or System.Diagnostics namespaces.

Logging and Assertion Facilities

The Debug and Trace classes provide error logging and assertion capabilities. These two classes are almost identical; the main differentiator is how they are used. The Debug class is used primarily in debug builds, while the Trace class is used in both debug and release builds.

For error logging and assertion, make use of the Debug and ...

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