Reputation: 11581
Do you know how to trace all method invocations in an .NET application. My current approach is to write trace at the beginning of each method like this
void DoSomething()
{
using(new Tracer(TraceCategory)
{
//Perform all action here
}
}
But it sucks as it clusters my code and I will have to write traces for all of my method.
Would there another way to record when a method is called, and when it finishes? All suggestions would be appreciate.
Upvotes: 1
Views: 1159
Reputation: 13399
You should use frameworks like Unity or PostSharp. Both of them have hooks for before method starting and after method finishing events.
Sample for PostSharp was already posted by Yahia.
Upvotes: 3