Skip to content
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

Serilog console logging with JsonFromatter #225

Closed
rajurh opened this issue Jun 24, 2020 · 5 comments
Closed

Serilog console logging with JsonFromatter #225

rajurh opened this issue Jun 24, 2020 · 5 comments

Comments

@rajurh
Copy link

rajurh commented Jun 24, 2020

I have been trying to use Serilog Console logging with JsonFormatter. When I enable option for console logging in code with .NET core we have option with JsonFromatter to renderMessage= true in its constructor which helps to render message and template in a nicer way and working well.

When I try to define and make it work using appsetting.json configuration for console logging I dont see an option to define "renderMessage" = true due to which when it logs in console I am not getting rendered message.

"formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"

As part of configuration setting if you could let me know how to enable render message option will be of great help.

@nblumhardt
Copy link
Member

Hi! To do this, install the Serilog.Formatting.Compact package, and use Serilog.Formatting.Compact.RenderedCompactJsonFormatter instead. HTH!

@rajurh
Copy link
Author

rajurh commented Jun 24, 2020

Hi, I didn't use RenderedCompactJson or CompactJsonFormatter because of following reason
Either of them doesn't provide both Message template and Rendered message until you define output message template which I wanted to avoid. What will be your recommendations

@nblumhardt
Copy link
Member

Hi! Just grabbing the source for CompactJsonFormatter and adding the @m field using the extra line in RenderedCompactJsonFormatter will do the job - the source is very, very short - it's easier to copy/modify than for us to support a wide variety of flags/options in the formatters. Hope this helps!

@btull89
Copy link

btull89 commented Mar 26, 2021

I also would like to be able to use the JsonFormatter and set "renderMessage" = true through appsettings.json.

@martinmine
Copy link

For those wondering, this is how you configure this after the 3.3.0 release:

{
  "Name": "File",
  "Args": {
    "path": "log.json",
    "rollingInterval": "Day",
    "retainedFileCountLimit": 7,
    "formatter": {
      "type": "Serilog.Formatting.Json.JsonFormatter, Serilog",
      "renderMessage": true
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants