How can I add a Trace() to every method call in C#?

Jon Tackabury picture Jon Tackabury · Feb 18, 2009 · Viewed 26k times · Source

I am having a hard time tracking down a lock issue, so I would like to log every method call's entry and exit. I've done this before with C++ without having to add code to every method. Is this possible with C#?

Answer

Dennis G. picture Dennis G. · Feb 18, 2009

Probably your best bet would be to use an AOP (aspect oriented programming) framework to automatically call tracing code before and after a method execution. A popular choice for AOP and .NET is PostSharp.