0

I used to hide my SQL database logs from Console/Debug by adding this line of code in the Program.cs:

builder.Host.UseSerilog((builderContext, config) =>
{
    config.ReadFrom.Configuration(builderContext.Configuration);
    config.Filter.ByExcluding(Matching.FromSource("Microsoft.EntityFrameworkCore.Database.Command"));
});

How to hide my SQL queries using the appsettings.json file?

"Serilog": {
    "MinimumLevel": {
        "Default": "Information"
    },
    "WriteTo": [
        {
            "Name": "Console",
            "Args": { "outputTemplate": "[{Timestamp:dd/MM/yyyy HH:mm:ss ffff zzz} {Level:u3}] {Message:lj}{NewLine}{Exception}" }
        },
        {
            "Name": "Debug",
            "Args": { "outputTemplate": "[{Timestamp:dd/MM/yyyy HH:mm:ss ffff zzz} {Level:u3}] {Message:lj}{NewLine}{Exception}" }
        },
    ],
    // Tried this but it does not work.
    "Filter": [
        {
            "Name": "ByExcluding",
            "Args": {
                "expression": "SourceContext = 'Microsoft.EntityFrameworkCore.Database.Command'"
            }
        }
    ],
    "Enrich": [
        "FromLogContext"
    ]
},  

1 Answer 1

0

I found a way by using the available Serilog options, even though its not the same, it does the hiding:

"Serilog": {
    "MinimumLevel": {
        "Default": "Information",
        "Override": {
            "Microsoft.EntityFrameworkCore.Database.Command": "Error"
        }
    },
...

Keeping the question open for a little in case someone knows a better variant.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.