Who called me?

Posted by Marcus Hammarberg on August 18, 2008
Here is a cool little code snippet with done with reflection that actually is quite handy. Especially in a logging situation.

I tweaked the code a bit to be not "WhoCalledMe" but rather "WhoIsTheCallerOfMe" and as such could hide most of the logging in a base class. This is easily done by changing the row
StackFrame stackFrame = stackTrace.GetFrame(1);
StackFrame stackFrame = stackTrace.GetFrame(2);
Of course then you'll have to check that the frame in question (2) exists.

If you liked this post ... here's more for you:

Published by Marcus Hammarberg on Last updated