CHAPTER 40

image

Logging and Debugging Techniques

The .NET Runtime provides a few facilities to make programming less dangerous. Conditional methods and tracing can be used to add checks and log code to an application, to catch errors during development, and to diagnose errors in released code.

Conditional Methods

Conditional methods are typically used to write code that performs operations only when compiled in a certain way. This is often used to add code that is called only when a debug build is made and is not called in other builds, usually because the additional check is too slow.

In C++, you would do this by using a macro in the include file ...

Get A Programmer's Guide to C# 5.0, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.