ILogger for ConnectionMultiplexer by NickCraver · Pull Request #2051 · StackExchange/StackExchange.Redis (original) (raw)
There are a few ways to make this faster on allocations - totally cool with any of them my thinking is:
- It should be analyzer enforced if possible
- It should work everywhere possible.
There exists today the signatures like LogInformation(ILogger, String, Object[]) and friends, but if we're formatting that message at all it's the same performance plus the object array in the end to get structured logging.
I was really hoping before tackling this that the interpolated string handler goodness in .NET 6+ (https://devblogs.microsoft.com/dotnet/string-interpolation-in-c-10-and-net-6/) would have landed in logging extension methods but alas this set of APIs didn't happen. I chatted with @stephentoub on this quite a while back and did poke at it, but the fundamental problem you arrive at is "that's not the shape of ILogger" in the end, so if that's your interface someone is calling the formatter in all the cases I could try to be more efficient in. It's entirely possible a smarter API design that I was capable of would still be a win here though, and if so: I'm all game for it.
In the example above my worry cases would be "touching ValueTuple again with a 1000 ft pole" and exceedingly high format count cases to maintain like exception messages today with something like 30-50+ args in play.
I'll keep hacking at making all the basics correct here, but if we can come up with optimal paths to go back through: yeah, absolutely. Do you wanna try a spike against this branch and see what we can do for options? Absolutely wanting to make this more efficient if we reasonably can.