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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

It is not working. For Verbose it returns error: Additional information: Configuration value 'Verbose' for category 'Microsoft' is not supported.
And when you try "Debug"?
Try "Trace", they renamed the logging levels.
Setting Logging:LogLevel:Microsoft to Trace does not help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.