Plus sign "+" causes one curly braces to go missing
See original GitHub issueDoes this issue relate to a new feature or an existing bug?
- Bug
- New Feature
Version of Serilog affected Serilog 2.5.0
Target framework
- netCore 2.0
- netCore 1.0
- 4.7
- 4.6.x
- 4.5.x
Current behavior? Logging a string that contains json with a plus sign “+” causes one of the last curly braces to go missing.
Seems to only be an issue when there is two curly braces at the end of an object. See the example code below.
Expected behavior? I would expect a + sign to not have this side effect.
If the current behavior is a bug, please provide the steps to reproduce the issue and if possible a minimal demo of the problem
var log = new LoggerConfiguration()
.WriteTo.Debug()
.CreateLogger();
log.Information("{\"id\":\"+\"}");
log.Information("{\"obj\":{\"id\":\"+\"}}"); // This will miss } at end in log
log.Information("[{\"obj1\":{\"id\":\"+\"}}, {\"obj2\":{\"id\":\".\"}}]"); // This will miss } at end of first object
log.Information("[{\"obj1\":{\"id\":\"+\"}}, {\"obj2\":{\"id\":\"+\"}}]"); // This will miss } at end of first object and last
log.Information("{\"obj\":{\"id\":\".\"}}");
log.Information("{t}", "{\"obj\":{\"id\":\"+\"}}"); // Workaround
Gives output [13:05:56 INF] {“id”:“+”} [13:05:56 INF] {“obj”:{“id”:“+”} <-- Notice missing } at end [13:05:56 INF] [{“obj1”:{“id”:“+”}, {“obj2”:{“id”:“.”}}] <-- Missing } at end of first object [13:05:56 INF] [{“obj1”:{“id”:“+”}, {“obj2”:{“id”:“+”}] <-- Missing } at end of both objects [13:05:56 INF] {“obj”:{“id”:“.”}} [13:05:56 INF] {“obj”:{“id”:“+”}}
A workaround by passing it in as a argument works, but i don’t think this is expected behaviour.
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
@bartelink You sure know how to trigger a coder. And @nblumhardt kindly pointed me in the right direction. So now i don’t have any excuses. 😉
Anyhow, big thanks for helping me out! And thanks for Serilog!
👍 I think it’s here:
https://github.com/serilog/serilog/blob/dev/src/Serilog/Parsing/MessageTemplateParser.cs#L251
The
IsValidInFormat()
method is a little bit suspect in how specific it is, given the variety of possible format specifiers, but that’s tangential 😃Thanks for raising the issue @zleepy , hope this answers your question, let us know if not.