StackTrace class performance

  • Thread starter Thread starter ernesto
  • Start date Start date
E

ernesto

Hi everybody:

I'm writing a log class that uses the StackTrace information in order
to write in the log files the name of the classes and methods that
produce every log entry.

Anyway, doing some profiling, I have found that the instantiation of
the StackTrace class takes a lot of time and turns my application
heavy.

There is a way to improve that performance? There is some workaround
about it or there is a way to reuse the StackTrace object to get the
last stack trace frames?

Regards,



Ernesto
 
ernesto said:
I'm writing a log class that uses the StackTrace information in order
to write in the log files the name of the classes and methods that
produce every log entry.

Anyway, doing some profiling, I have found that the instantiation of
the StackTrace class takes a lot of time and turns my application
heavy.

There is a way to improve that performance? There is some workaround
about it or there is a way to reuse the StackTrace object to get the
last stack trace frames?

A stack trace cost.

If you only need current method name then
MethodInfo.GetCurrentMethod().Name
is faster than
(new StackTrace(true)).GetFrame(0).GetMethod().Name

Arne
 
Back
Top