Tracer.GetExecutingMethodName changed in 5.0

Topics: Logging Application Block
Feb 8, 2012 at 8:28 PM


In the Logging Application Block version 4.0 the call GetExecutingMethodName would return the method name that was on top of the stack..

whereas in 5.0 it is the last method name of the stack.. This is becuase we don't return/break out of the loop when we find a match which 4.0 version does

Is this as designed or a bug?



Feb 8, 2012 at 10:00 PM

I didn't really see the behavior that you described.  The code is virtually unchanged between 4.1 and 5.0.515.0.

The only difference is that in version 5 there is a check to not return any methods from TraceManager:

private string GetExecutingMethodName()


    string result = "Unknown";

    StackTrace trace = new StackTrace(false);


    for (int index = 0; index < trace.FrameCount; ++index)


        StackFrame frame = trace.GetFrame(index);

        MethodBase method = frame.GetMethod();

        Type declaringType = method.DeclaringType;

        if (declaringType != GetType() && declaringType != typeof(TraceManager))


            result = string.Concat(method.DeclaringType.FullName, ".", method.Name);





    return result;



Basically the only change is the check against TraceManager.  A quick sample on my end shows that the method name is correctly logged.  Perhaps it's a specific case?  What is your exact scenario?

Randy Levy
Enterprise Library support engineer 

Feb 8, 2012 at 10:10 PM

Hi Randy,

You are correct. My fault, i was looking at the wrong code... should have slept in! ;-)

thx! sorry for raising this issue.