How performant is StackFrame?

前端 未结 7 1236
鱼传尺愫
鱼传尺愫 2020-12-01 02:18

I am considering using something like StackFrame stackFrame = new StackFrame(1) to log the executing method, but I don\'t know about its performance implication

7条回答
  •  盖世英雄少女心
    2020-12-01 02:37

    I know what you mean, but this example result is overshoot. Executing the GetCurrentMethod even when logging is turned off is a waste. It should be something like:

    if (loggingEnabled) TraceCall(MethodBase.GetCurrentMethod());  
    

    Or if you want the TraceCall always executed:

    TraceCall(loggingEnabled ? MethodBase.GetCurrentMethod() : null);
    

提交回复
热议问题