Suppress SQL Queries logging in Entity Framework core
If you're using built-in logger, you can add filter to you ILoggingBuilder in Program.cs.
So, it can look like:
WebHost.CreateDefaultBuilder(args)
// ...
.ConfigureLogging((context, logging) => {
var env = context.HostingEnvironment;
var config = context.Configuration.GetSection("Logging");
// ...
logging.AddConfiguration(config);
logging.AddConsole();
// ...
logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
})
// ...
.UseStartup<Startup>()
.Build();
Don't know if this is still an active question, but this is my solution, override the minimum level for "Microsoft.EntityFrameworkCore.Database.Command"
Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(loggingLevelSwitch)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", Serilog.Events.LogEventLevel.Warning)
.Enrich.WithProperty("app", environment.ApplicationName)
.Enrich.FromLogContext()
.WriteTo.RollingFile($"./Logs/{environment.ApplicationName}")
.CreateLogger();
you can also have this on the appconfig.json
"Serilog": {
"Using": [ "Serilog.Sinks.Console" ],
"MinimumLevel": {
"Default": "Verbose",
"Override": {
"Microsoft": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"WriteTo": [
{
"Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:u}] [{Level:u3}] {SourceContext} {Message:lj}{NewLine}{Exception}"
}
},
],
"Enrich": [ "FromLogContext", "WithExceptionDetails" ]
}