Cysharp / ZLogger

Zero Allocation Text/Structured Logger for .NET with StringInterpolation and Source Generator, built on top of a Microsoft.Extensions.Logging.
MIT License
1.16k stars 81 forks source link

Support for named arguments #10

Closed theolivenbaum closed 4 years ago

theolivenbaum commented 4 years ago

Would be nice to have support for named arguments on the format method, without having to rewrite all log messages. I guess in a first pass, they could all be interpreted as incrementing argument numbers, as they're usually not repeated in the log message.

 //this works

Logger.ZLogInformation("Log value {0}", 1234);

 //this throws "Input string was not in a correct format." in Cysharp.Text.FormatParser.Parse
Logger.ZLogInformation("Log value {VALUE}", 1234);
neuecc commented 4 years ago

It is called Message Templates. It bothered me, but I omit it. Because we wanted to avoid being unable to use the implementation of ZString and having multiple implementations, it is unsupported.

theolivenbaum commented 4 years ago

Ok makes sense. It seems like the normal Logging methods work fine (with the extra cost of allocations), so we'll manually update where needed to the new syntax. Thanks!