Aspect-Oriented Programming (AOP) and Tracing
I've been interested in Aspect-Oriented Programming (AOP) for some time now, but I hadn't actually experimented with it myself until recently. That's not totally true, since most O/R mappers use AOP in their implementation, but I've only been a consumer of AOP in those cases. For my own experiment, I decided to dig up an old MSDN article by Dharma Shukla, Simon Fell, and Chris Sells that used AOP for tracing. By just decorating your class with an attribute, their code automatically adds tracing when you enter each method (with all your parameters included) and when you leave each method (with the return value included). I modified it a little in my experiment to make explicit tracing calls much easier, and I also added a config switch to disable or enable the actual tracing output. You could similarly modify it to output the trace to different “listeners”, or even add severity levels, but I'm just experimenting so I haven't done that yet. This is all really cool stuff, especially since its so much easier to actually consume than other tracing methods like Log4Net, the Exception Management Application Block, or custom Trace Listeners. By the way, that last one is an excellent article written by my good friend Jerry Dennany, who has an occassional clue here on these weblogs too. Anyhow, my question to my few readers out there is how much does this context-bound call interception technique affect performance when you compare it to the other more traditional methods? Also, are there any other things to worry about with these techniques, whether it be for tracing, persistence, security, or something entirely different? And finally, what other uses have you dreamed up, or just heard about, for AOP, and what has been your experience using AOP for such things?