【问题标题】:Entity Framework Core / 7 SQL LoggingEntity Framework Core / 7 SQL 日志记录
【发布时间】:2017-10-03 00:32:52
【问题描述】:

查看this similar question 我需要做同样的事情,即我希望将 SQL 复制到我的输出中,但我需要为EF Core / 7 完成它

我尝试添加LogFactory,如this example所示

但这也没有产生 SQL 输出……我错过了什么?

【问题讨论】:

  • 您是否在Startup.cs 中配置了您的loggerFactory
  • 请告诉我怎么做...

标签: asp.net-core entity-framework-core


【解决方案1】:

EF Core 1.1 example you linked to 应该可以工作,假设您在 Startup.csConfigure 方法中有以下内容:

public void Configure(
    IApplicationBuilder application, 
    IHostingEnvironment environment, 
    ILoggerFactory loggerFactory) {

        loggerFactory
            .AddConsole(LogLevel.Debug)  // This will output to the console/terminal
            .AddDebug(LogLevel.Debug);   // This will output to Visual Studio Output window

        // Your additional configuration here...
}

【讨论】:

  • 仅供其他遇到相同问题的人阅读this article。因为这个答案不是很有帮助,除了@Matt 只添加了脚手架代码。
  • 但它回答了他的问题:(
【解决方案2】:

您还可以安装 dotnet 工具。该存储库包含 .NET Core CLI 的命令行工具。

运行 dotnet watch run,调试应用程序并向您显示任何已执行的 sql 查询。

我正在使用 VS 代码进行编码,但不能 100% 确定它是否可以在 Visual Studio 中工作。

【讨论】:

    猜你喜欢
    • 2017-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    相关资源
    最近更新 更多