-
Notifications
You must be signed in to change notification settings - Fork 794
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Support for Interpolated String #639
Comments
I'm not sure how support for What would you do for scenarios like Also, for reference; C# 6 string interpolation and Serilog |
@Pvlerick - neat blog post! I too had thought about this in the past and, even with @nblumhardt 's blog post in mind, it's worth exploring. @khellang is right about the given scenario. Part of me thinks that "perfect is the enemy of the good" and the referenced Roslyn issue will eventually provide a solution. In the meantime logging with dummy placeholders wouldn't be the end of the world. The other part of me worries that something is built and then breaks in future. Food for thought 🍴 |
@IanYates thanks. I agree that this is kind of a can of worms and as you rightly pointed it might lead to something fragile that could break in the future. I'll keep investigating and see if there is a way to make this work nicely with regards to @khellang's and @nblumhardt's points and we'll see. |
easy: I had to implement it as extension with "_"-suffix, because otherwise roslyn invokes
Does anyone want to submit a PR? |
I've just published a library (with extensions to Serilog, NLog, and Microsoft ILogger) that allows writing log messages using interpolated strings and yet defining the property names through different syntaxes. |
When using C# 6.0, it is currently not possible to use interpolated strings to log.
Taking the example from Serilog's home page
At the moment, there is no way to use the interpolated string and use Serilog's serializer.
It would be nice to be able to use interpolated string while at the same time take advantage of Serilog's serializer, using something like:
This is doable using methods that expect a
FormattableString
, however if there are overloads also taking a string, the string will be preferred by the compiler. One way to make it work is to have all the string overloads being extension methods instead of instance methods.I wrote a gist to demonstrate: https://gist.github.com/Pvlerick/f4d0876b82f85ef369d0
The implementation is quick and dirty but only serves to prove that it's doable. There might also be ways to implement that that I didn't think of, of course 😄
Also, an potential issue is that this relies on the compiler's behaviour, which probably won't be in the specifications (I wrote an blog post on this with more details). However I think it is possible to make the implementation robust enough to work in all cases.
The text was updated successfully, but these errors were encountered: