Possible Duplicate:
How I can get the calling methods in C#
I have a Log
class that's supposed to prepend its client's class and method to the logged message like this:
[ClientClass.ClientMethod] This is the logged message.
And I'm looking for a safe way to obtain these values from the Log
class, without passing it as a parameter from the client. I have tried this so far:
var stackFrame = new StackFrame(StackFramesToSkip);
var method = stackFrame.GetMethod();
return string.Format("[{0}.{1}] {2}", method.DeclaringType.Name, method.Name, message);
However, this method doesn't always yield the calling method. Especially when working with multiple threads.
Is there a safe way of doing this? I'm out of ideas.
Thanks!