Does anyone has a good solution for a C# version of the C++ __FUNCTION__ macro? The compiler does not seem to like it.
I use this:
public static string CallerName([CallerMemberName] string callerName = "")
{
return callerName;
}
Usage example:
s_log.DebugFormat("{0}", CallerName());
The down side of using it is that every time you want to print the caller name, you need to jump to the function ==> time consuming & performance hit! So, I use it for debugging perpose and if I need to print also in production code, I usually inline the function name into the log.Debug, e.g. :
s_log.Debug("CallerName");
HTH..