Skip to content

JsonFormatter RenderedMessage writes invalid output #1924

@Mikey1223

Description

@Mikey1223

Description
When using JsonFormatter with renderMessage enabled to write console output, the JSON output is not created correctly and results in invalid JSON.

Reproduction

  1. Configure a default logger with a sinkConfiguration that uses the JsonFormatter with renderMessage = true
  2. Log a message
  3. The output results in invalid quoted JSON at the renderedMessage with an extra quote, for example:

{ "Timestamp": "2023-06-21T09:48:56.0952245+02:00", "Level": "Error", "MessageTemplate": "Testmessage with value: {TestMessageValue}"", "RenderedMessage": "Testmessage with value: 1", "Properties": { "TestMessageValue": "1" } }

Expected behavior
Using Serilog 2.12.0 the output would result in valid JSON, we would expect the same behaviour in the latest version.

Relevant package, tooling and runtime versions
Serilog 3.0.0

Additional context
Code where the extra quote is added can be found here:
https://github.com/serilog/serilog/blob/main/src/Serilog/Formatting/Json/JsonFormatter.cs#L69

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions