Skip to content

JsonConsoleFormatter: number and boolean properties should not be converted to string #39870

Closed

Description

@alefranz

Description

Currently the new JsonConsoleFormatter converts all the values of the key/value pairs in both the state and scopes to string.
As json supports numbers and booleans, I think the built-in value types should not be converted to string.
Using number would allow to write range queries once ingested on a log analysis system.

/cc @maryamariyan

Sample code

logger.LogInformation("This is a message with a {Number}", 1);

Current result

{
  "Timestamp": "2020-07-23T21:47:33.7369359\u002B01:00",
  "EventId": 0,
  "LogLevel": "Information",
  "Category": "JsonLogging.Program",
  "Message": "This is a message with a 1",
  "Number": "1",
  "{OriginalFormat}": "This is a message with a {Number}",
}

Expected result

{
  "Timestamp": "2020-07-23T21:47:33.7369359\u002B01:00",
  "EventId": 0,
  "LogLevel": "Information",
  "Category": "JsonLogging.Program",
  "Message": "This is a message with a 1",
  "Number": 1,
  "{OriginalFormat}": "This is a message with a {Number}",
}

Regression?

No, part of a new feature

Activity

  1. Dotnet-GitSync-Bot commented on Jul 23, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  2. added
    untriaged
    on Jul 23, 2020
  3. alefranz commented on Jul 23, 2020

    @alefranz
    ContributorAuthor

    @maryamariyan if this change is agreed, I could work on a PR if it helps.

  4. maryamariyan commented on Jul 27, 2020

    @maryamariyan
    Contributor

    @maryamariyan if this change is agreed, I could work on a PR if it helps.

    Sure. @alefranz go for it :)

  5. removed
    untriaged
    on Jul 27, 2020
  6. added this to the 5.0.0 milestone on Jul 27, 2020
  7. ghost locked as resolved and limited conversation to collaborators on Dec 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions