Add support for FormattableString
See original GitHub issueI think it would be a nice addition to the arsenal of ZeroLog to support the somewhat unknown c# interpolated string feature called ForamttableString
.
This would basically allow users to call ZeroLog with interpolated strings:
log.InfoInterpolated($"Tomorrow ({tomorrow}) will occur in {numberOfSecondsUntilTomorrow} seconds");
The theory behind this is that ZeroLog would get a FormattableString instance fed into the *Interpolated
variants of the logging functions that would have to be added to ZeroLog and to the StringFormatter project.
The reason behind adding yet another overload for this purpose is that apprently the c# compiler has a feature/issue where having two functions that only differ by having a string/FormattableString parameter leads to the string variant being always selected by the compiler:
https://github.com/dotnet/roslyn/issues/46
http://blog.engdahls.dk/2016/08/how-to-overload-string-and.html
Any thoughts about this?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
Yes, it allocates the
FormattableString
, plus anobject[]
array to hold the values, and it needs to box the values when they’re value types.See here:
Gets compiled to:
Ok, it’s maybe a tiny bit late, but interpolated string support is now available in v2, and does not allocate thanks to interpolated string handlers in C# 10. 🙂