admin管理员组文章数量:1332345
I am trying to get EF Core to stop writing SQL to my log files. I am using NLog. I have the following in my appsettings.json:
"Logging":
{
"LogLevel":
{
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
I tried setting the following when creating the context:
services.AddDbContext<TContext>(o =>
{
o.UseSqlServer(connectionString);
o.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuting, LogLevel.Warning)));
});
And I tried something like this when adding the logging:
services.AddLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
logging.AddConfiguration(configuration.GetSection("Logging"));
logging.AddNLog();
logging.AddFilter("Microsoft", LogLevel.Warning);
});
Every time is still logs the Info for the logging:
2024-11-20 15:13:36.3284||INFO|Microsoft.EntityFrameworkCore.Database.Command|Executed DbCommand (34ms)...
What am I missing?
I am trying to get EF Core to stop writing SQL to my log files. I am using NLog. I have the following in my appsettings.json:
"Logging":
{
"LogLevel":
{
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
I tried setting the following when creating the context:
services.AddDbContext<TContext>(o =>
{
o.UseSqlServer(connectionString);
o.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuting, LogLevel.Warning)));
});
And I tried something like this when adding the logging:
services.AddLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(LogLevel.Trace);
logging.AddConfiguration(configuration.GetSection("Logging"));
logging.AddNLog();
logging.AddFilter("Microsoft", LogLevel.Warning);
});
Every time is still logs the Info for the logging:
2024-11-20 15:13:36.3284||INFO|Microsoft.EntityFrameworkCore.Database.Command|Executed DbCommand (34ms)...
What am I missing?
Share Improve this question edited Nov 24, 2024 at 12:14 Rolf Kristensen 20k2 gold badges58 silver badges82 bronze badges asked Nov 20, 2024 at 21:18 Tyrel Van NiekerkTyrel Van Niekerk 1,7125 gold badges23 silver badges39 bronze badges1 Answer
Reset to default 0Your code looks correct; here are my suggestions.
- My best guess is that something you may have specified in the Nlog config is overriding the configurations in
appsettings.json
.
To test this, could you add the following inside services.AddLogging()
? Since this filter is at the code level, It should help override NLog settings.
logging.AddFilter("Microsoft.EntityFrameworkCore.Database.Command", LogLevel.Warning);
- Do you have an Nlog.config file, and if so, confirm if a more permissive rule is specified for
Microsoft.EntityFrameworkCore.Database.Command
?
本文标签: entity frameworkSuppress Logger output from EF Core SQL when using NLogStack Overflow
版权声明:本文标题:entity framework - Suppress Logger output from EF Core SQL when using NLog - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742327569a2454031.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论