Generally you can create a StackTrace anywhere you want:
StackTrace st = new StackTrace();
Then it's just about cycling through the StackFrames:
StackFrame[] sf = st.GetFrames();
// in case your PrintLog has overloads or recursions
// it may appear several times in the stack
string ownName = "PrintLog";
MethodInfo curMethod = null;
for(int i = 0; i < sf.Length; i++) {
curMethod = sf[i].GetMethod();
if(ownName != curMethod.Name)
break;
}
Console.WriteLine("Call from function {0}, type {1}",
curMethod.Name,
curMethod.DeclaringType.Name);
You could even identify the class and parameters (you have the MethodInfo object to play around with)
Personally I put the Time TID caller class+type+name into my logging context.
As I understand you wanted to parse the function name and type to the PrintLog
function. Thats just messy!
The beauty of this approach is, that you don't have to do that. You can retreive the name and type of the caller within the PrintLog
method.