serilog / serilog-settings-configuration

A Serilog configuration provider that reads from Microsoft.Extensions.Configuration
Apache License 2.0
444 stars 129 forks source link

Default formatter overrided by JSON formatter when using appsetting.json #382

Closed AdisonCavani closed 1 year ago

AdisonCavani commented 1 year ago

I want to use JSON formatter in production, but preserve default formatter in development. In prod, everything is fine, but in development it's still using JSON formatter.

How can I use default formatter with this configuration?

I'm using this configuration files.

builder.Host.UseSerilog((ctx, cfg) => cfg.ReadFrom.Configuration(ctx.Configuration));

appsettings.json:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console" ],
    "MinimumLevel": {
      "Default": "Information"
    },
    "WriteTo": [
      {
        "Name": "Console",
        "Args": {
          "formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
        }
      }
    ],
    "Enrich": [ "FromLogContext", "WithThreadId" ]
  }
}

appsettings.development.json:

{
  "Serilog": {
    "Using": [ "Serilog.Sinks.Console" ],
    "MinimumLevel": {
      "Default": "Information"
    },
    "WriteTo": [
      {
        "Name": "Console"
      }
    ],
    "Enrich": [ "FromLogContext", "WithThreadId" ]
  }
}
nblumhardt commented 1 year ago

The trick to successful dev/prod configuration with this library is not to put much (or anything at all) related to Serilog in appsettings.json. Rather, put full configurations in each of appsettings.Development.json and appsettings.Production.json. This will avoid a whole range of quirky interactions between the two setups.

Hope this helps, Nick

AdisonCavani commented 1 year ago

I managed to resolve the issue by adding default theme to args.