Serilog how to remove a sink in the appsettings.production.json

43 Views Asked by At

Serilog works and logging is great. However, I would like to turn off sinks using an override environment. Is there a way to specifically turn off the console sink using appsettings.production.json?

It looks like the XML version of appsettings supports removing values. And the JSON documentation states to use "Name":{}, but how would this work in this case? Even putting in "WriteTo" : {} in the production settings doesn't work as all the WriteTo entries in the array are added from both settings.


The default appsettings.json contains the following

"Serilog": {
    "MinimumLevel": {
        "Default": "Information"
    },
    "WriteTo": [
        {
            "Name": "File",
            "Args": {
                "path": "Seri.log",
                "rollingInterval": "Day"
            }
        },
        { "Name": "Console" }
    ]
},

The production environment contains this:

"Serilog": {
    "MinimumLevel": {
        "Default": "Information"
    },
    "WriteTo": [
        {
            "Name": "File",
            "Args": {
                "path": "Seri.log",
                "rollingInterval": "Day"
            }
        }
    ]
},
0

There are 0 best solutions below