question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use JSON event formatting with appsettings.json

See original GitHub issue

I wanted to log in json files with .Net Core 2.2. However, it writes my logs in a non json format

Here is my appsettings.json file

  "Serilog": {
    "MinimumLevel": "Fatal",
    "WriteTo": [
      {
        "Name": "Async",
        "Args": {
          "configure": [
            {
              "Name": "File",
              "Args": {
                "path": "..\\Logs\\log.json",
                "formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact",
                "rollingInterval": "Day",
                "retainedFileCountLimit": 5, 
                "fileSizeLimitBytes": 1073741824, 
                "rollOnFileSizeLimit": true, 
                "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}{NewLine}"
              }
            }
          ]
        }
      }
    ],
    "Properties": {
      "Application": "Common feature in WebApi demo"
    }
  },

I even tried to delete the outputTemplate field but it always writes as 2019-06-05 10:42:32.952 +01:00 [Fatal] {My data}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
nblumhardtcommented, Jun 5, 2019

Hi Pedro,

The problem here is that outputTemplate and formatter are mutually-exclusive: only one or the other should be specified. Currently, when the configuration is ambiguous, the library will just choose one itself, which is outputTemplate in this case.

Removing the outputTemplate option will get this working.

HTH!

0reactions
skomis-mmcommented, May 11, 2020

Hi @PedroS11 ,

Just checked with your config, it works. If you still hit the issue, try to update to the latest versions of the packages. If it doesn’t help, please re-open issue. Thanks

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appsettings.json based on environments doesn't load
Firstly you need to create launchSettings.json in Properties. enter image description here. With content some thing like this.
Read more >
Application Settings (appsettings.json)
All of the application's settings are contained in a file named appsettings. json. Any changes to the appsettings. json file will require ...
Read more >
Customized JSON formatting with Serilog
Log event levels, messages, stack traces and other properties introduce ... This post collects all kinds of JSON formatting examples using ...
Read more >
The settings from the appsettings.json file
In this article, we will explain what settings are available in this file, what they are used for, and how to use these...
Read more >
Cloud Explorer corrupts JSON formatting
Hi,. Today I was using cloud explorer to make a quick change to appsettings.json on a UAT version of a deployed web app...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found