3 ms·
Meh. The payoff in format-string conditional log statements is in avoiding the cost of string construction only to throw it away--NOT to avoid the cost of eval
by sk5t 14y ago
Meh. The payoff in format-string conditional log statements is in avoiding the cost of string construction only to throw it away--NOT to avoid the cost of evaluating operands.
I have always preferred the NLog style, where the default .Debug, .Warn, etc., functions use good old .NET format strings and a params argument.
logger.Debug("Thing {0} happened at {1:R}", thing, thing.CompletionDate);
- flyinRyan 14y agoNo, the issue was: log.Debug("Thing {0} happened", o.expensive_call()) could end up calling some method that took a very long time to run, only to be thrown away in the end. String construction isn't that big of a deal and their new API could avoiding doing it if the message won't be used.