1

How can I log all queries to output when using DbContext?

In the past I get all queries (SQLs) in Output window in Visual studio 2015. I don't know when this has stopped.

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

And appsettings.json:

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

This is not working. And I think this means the logs should be in output.

Edited:

I think it is not possible without some work around. GitHub1, GitHub2.

For now I went with SQL Server Profiler.

Community
  • 1
  • 1
Makla
  • 9,899
  • 16
  • 72
  • 142

1 Answers1

0

Set the Microsoft LogLevel in appsettings.json to Debug or Verbose. The default LogLevel is only used if there isn't a more specific level, and Entity Framework looks at the Microsoft level.

AddConsole is what makes the affected logs get printed to stdout according to the Logging section you pass in.

Jesper
  • 7,477
  • 4
  • 40
  • 57