【问题标题】:ASP.NET Core 1.1 log all DbContext queries to output windowASP.NET Core 1.1 将所有 DbContext 查询记录到输出窗口
【发布时间】:2017-07-12 05:40:06
【问题描述】:

使用DbContext 时如何将所有查询记录到输出?

过去,我在 Visual Studio 2015 的“输出”窗口中获取所有查询 (SQL)。我不知道这何时停止。

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, DbSeeder dbSeeder)
{
    loggerFactory.AddConsole(Configuration.GetSection("Logging"));
    loggerFactory.AddDebug();

还有 appsettings.json:

  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Debug",
      "System": "Information",
      "Microsoft": "Information"
    }

This 不工作。我认为this 意味着日志应该在输出中。

已编辑:

我认为如果没有一些工作是不可能的。 GitHub1, GitHub2.

现在我使用 SQL Server Profiler。

【问题讨论】:

    标签: entity-framework asp.net-core


    【解决方案1】:

    将 appsettings.json 中的 Microsoft LogLevel 设置为 DebugVerbose。只有在没有更具体的级别时才使用默认的 LogLevel,而 Entity Framework 会查看 Microsoft 级别。

    AddConsole 是根据您传入的 Logging 部分将受影响的日志打印到标准输出的原因。

    【讨论】:

    • 它不工作。对于 Verbose,它返回错误:附加信息:不支持类别“Microsoft”的配置值“Verbose”。
    • 当你尝试“调试”时?
    • 尝试“Trace”,他们重命名了日志级别。
    • 设置 Logging:LogLevel:Microsoft to Trace 没有帮助。
    猜你喜欢
    • 2021-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-27
    • 2018-04-27
    相关资源
    最近更新 更多