4 ms·
Anecdote about log4net, a popular .Net logging library: Once, when working on a shipping desktop application, we got to the point where we had to care about pe
by gwbas1c 5y ago
Anecdote about log4net, a popular .Net logging library:
Once, when working on a shipping desktop application, we got to the point where we had to care about performance. When we turned on a CPU usage trace, the highest CPU consumer by a few orders of magnitude was the logger.
That surprised everyone, so we dug in a little deeper. Turns on log4net's default behavior is to calculate a complete stack trace for every logging statement, even if the stack trace isn't being logged.
Now, there may be good reasons to log a stack trace now and then, especially if you're trying to diagnose a difficult-to-reproduce bug. But, it's trivial to calculate the stack trace yourself.
When we reconfigured log4net to not calculate stack traces, our CPU usage lowered dramatically.
Lesson learned: Don't ship code with obscure features enabled that are performance pigs. There's no reason to calculate stack traces on each logging statement when the stack trace isn't being logged.