Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To turn off HTTP request tracking in Serilog's appsettings.json, you need to update the configuration of the Serilog.AspNetCore package in the appsettings.json file. You can do this by adding the following line to the "Serilog" section of the appsettings.json file:

"Serilog": {
    "MinimumLevel": {
        "Default": "Information",
        "Override": {
            "Microsoft": "Warning",
            "System": "Warning"
        }
    },
    "WriteTo": [
        {
            "Name": "Console"
        },
        {
            "Name": "File",
            "Args": {
                "path": "logs/log.json",
                "formatter": "Serilog.Formatting.Json.JsonFormatter, Serilog"
            }
        }
    ],
    "Enrich": [ "FromLogContext", "WithMachineName", "WithThreadId" ],
    "Properties": {
        "Application": "MyApplication"
    },
    "AspNetCore": {
        "RequestLog": {
            "LogLevel": {
                "Default": "Warning",
                "Microsoft": "Warning",
                "Microsoft.AspNetCore.StaticFiles": "Warning"
            }
        }
    }
}

In the "Serilog.AspNetCore" section, under "RequestLog", you can see the "LogLevel" field. Change the value of "Default" to a higher level than "Information". For example, you can set it to "Warning" to turn off HTTP request tracking.

    "AspNetCore": {
        "RequestLog": {
            "LogLevel": {
                "Default": "Warning",
                "Microsoft": "Warning",
                "Microsoft.AspNetCore.StaticFiles": "Warning"
            }
        }
    }