February 18, 2019
Hot Topics:

Whammy Tracing: Hassle-Free .NET Debugging

  • August 7, 2006
  • By Paul Kimmel
  • Send Email »
  • More Articles »

When I write an application with 40 or 50 thousand lines of code, its major capabilities can be tedious to debug line by line. I'd rather run these features at full speed and then go back and audit what actually occurred. The debugging tool that this article discusses, called the Whammy, provides an easy way to do that.

In a very unobtrusive way, the Whammy permits you to use the .NET Framework to add detailed tracing information to your application while writing very little code. For example, if you wrote code like the following:

   "Main called at {0}", DateTime.Now))

The Whammy is for you. It achieves effectively the same result, but with a lot less typing (as I have implemented it):


Author Note: Whammy comes from the idea that this code automatically answers the question 'who am I' about the calling method. Pronounced fast as one word, Who-Am-I becomes Whammy. That's my story and I am sticking to it.

By reading this article, you will learn about the Whammy and its corresponding technologies, ConditionalAttribute, the StackFrame and StackTrace objects, and reflection.

Using the ConditionalAttribute to Remove Deployed Code

You can apply the ConditionalAttribute, which takes a string argument, to a class or method. The string or conditional argument, if defined, permits calls to the conditional classes or methods. Code tagged with the conditional attribute is always emitted to MSIL (intermediate language code), but if the string is not defined, those calls are ignored.

To define a conditional string constant, use the #define pragma, as in the following example:

#define "MY_STRING"

Obtaining a StackFrame and StackTrace Object

Two of the many interesting features that the System.Diagnostics namespace defines are the StackTrace and the StackFrame. The StackTrace is an ordered collection of StackFrames; a StackFrame is all of the information about a single, literal call stack. StackFrames include information about the method called, arguments passed to that method, and from there, all kinds of information that you can glean through reflection.

Page 1 of 2

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date