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"
]
},