Entity Framework Core 的 SQL 日志记录

日志配置通常由 appsettings {Environment} .json 文件的 Logging 部分提供 。 若要记录 SQL 语句,请将
"Microsoft.EntityFrameworkCore.Database.Command": "Information" 添加到 appsettings.Development.json 文件:
 
{
    "ConnectionStrings":{
        "DefaultConnection":"Server=(localdb)\\mssqllocaldb;Database=MyDB- 2;Trusted_Connection=True;MultipleActiveResultSets=true"
    },
    "Logging":{
        "LogLevel":{
            "Default":"Information",
            "Microsoft":"Warning",
            "Microsoft.Hosting.Lifetime":"Information",
            "Microsoft.EntityFrameworkCore.Database.Command":"Information"
        }
    },
    "AllowedHosts":"*"
}

 

posted @ 2022-05-19 17:11  Tammytan  阅读(127)  评论(0编辑  收藏  举报