2 ms·
One cool feature of C# interpolated strings is that they are lazy. Many loggers used to implement their own interpolation because something like log.trace(
by orthoxerox 2y ago
One cool feature of C# interpolated strings is that they are lazy. Many loggers used to implement their own interpolation because something like
log.trace($"Entering iteration {i} for customer {c.ID} [{c.ShortName}]");
in a hot loop would call string.Concat every time it was called before the logger could bail out of the method.
C# lets you declare an overload that accepts a `DefaultInterpolatedStringHandler` (or your own custom implementation of the handler pattern) and this overload will take precedence and allow you to delay the building of the string until after you've checked whether logging it is required.