private static string GetCaller(int framesToSkip = 0)
{
string result = string.Empty;
int i = 1;
while(true)
{
// Walk up the stack trace ...
var stackFrame = new StackFrame(i++);
MethodBase methodBase = stackFrame.GetMethod();
if(methodBase == null)
break;
// Here we're at the end - nomally we should never get that far
Type declaringType = methodBase.DeclaringType;
if(declaringType == null)
break;
// Get class name and method of the current stack frame
result = string.Format("{0}.{1}", declaringType.FullName, methodBase.Name);
// Here, we're at the first method outside of SimpleLog class.
// This is the method that called the log method. We're done unless it is
// specified to skip additional frames and go further up the stack trace.
if(declaringType != typeof(SimpleLog) && --framesToSkip < 0)
break;
}
return result;
}