.net-core - 如何为上下文禁用日志

标签 .net-core entity-framework-core

我也升级到了 .net core 2.2 和 EF 2.2。现在,当我从 DbSet 中获取一个表时,对于我表中的每一行,都有一个日志行,并且它需要永远。由于我在 .net core 2.0 中没有此日志,因此如何禁用它?

例如:对于日志行,我每一行都有这个:

[15:58:02 DBG] Context 'BookContext' started tracking 'Book' entity.
 Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see key values.

因为我的表有 23000 条记录,所以我也有 23000 行日志!

我的 serilog 日志配置如下所示:

"Serilog": {
        "MinimumLevel": {
            "Default": "Debug",
            "Override": {
                "Microsoft": "Debug"
            }
        },

最佳答案

你可以这样做

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

关于.net-core - 如何为上下文禁用日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55715877/

相关文章:

c# - ASP.NET 核心 2 : What could be the code behind a "many-to-one" relationship in this case?

c# - EF Core 2.1 中的全文搜索?

entity-framework-core - 数据库优先,但只是数据库的一个子集

oracle - ORA-12570 : Network Session: Unexpected packet read error

c# - 使用参数从 .Net Core 运行 bash 命令

c# - .NET Core 2.0 Soap 客户端调用失败,错误代码为 "WinHttpException: The operation timed out"

entity-framework - 我可以在 Windows Phone 8 上使用 Entity Framework 吗

c# - 为什么变量名作为下划线字符 ("_")不适用于解构

c# - 迁移 EF Core 表

c# - EF Core 2.1.0 设置默认字符串长度和列类型