-
Notifications
You must be signed in to change notification settings - Fork 798
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
Numeric format specifier not respected #1323
Comments
Thanks for the note! This is indeed a bug; I think it might have evaded us because it does not affect the console sink; I get the correct output in Serilog.Sinks.Console, but in Serilog.Sinks.File I see:
The code that should be responsible for passing through the correct numeric format is: https://github.com/serilog/serilog/blob/dev/src/Serilog/Events/ScalarValue.cs#L90 - needs some breakpoint debugging to work out what's gone wrong. |
Here is what I found: File sink internally use MessageTemplateTextFormatter.
Then, on MessageTemplateTextFormatter.cs line 90-93
logEvent.Template is "{x = {x:X8}}" but pt.Format is "lj" (pt is PropertyToken "{{Message:lj}}") Since the "format" argument of MessageTemplateRenderer.Render(), pt.Format, contains a "j", "x" is rendered using JsonValueFormatter in MessageTemplateRenderer.RenderValue(). As a result, x is rendered as "16" |
Thanks for looking into this; you've reminded me that we've been looking at some related behavior lately (CC @tsimbalar). It's going to require some thought, at least around how to avoid the confusion/footgun. |
So I guess we are not going to fix this at this moment? |
…N defaults are selected
@csleead I have #1325 in the works |
…N defaults are selected
Does this issue relate to a new feature or an existing bug?
What version of Serilog is affected? Please list the related NuGet package.
Serilog 2.8.0
What is the target framework and operating system? See target frameworks & net standard matrix.
Please describe the current behavior?
The hex numeric format specifier does not work unless supplied using standard C# string interpolation. This means I cannot use structured logging if I wish to retain the formatted string in the standard log output.
Please describe the expected behavior?
Apologies in advance if this is not how it's meant to work. I tried looking for documentation addressing this specific case and couldn't (easily) find it, however, https://github.com/serilog/serilog/wiki/Writing-Log-Events states:
The text was updated successfully, but these errors were encountered: