Friday, February 16, 2007

Class Logging and tracing - approach using custom attributes

If, for debugging purposes, you want to see what is going on in your .Net code, one approach would be to add something like

Log.Debug("FindCustomers -> enter method")


Into each method you are interested in.
Another, more generic and actually pretty cool approach would be to "instrument" your classes using custom attributes.
A sample approach is shown here. (Overlook the repeated and dorky use of the term "spy" :) ).

The drawback is that using the above approach, your classes would have to inherit from a common base class ... but maybe there is a way around that and just use the attribute ...

No comments: