Efcore: Entity Framework logs not showing up anymore after migration to .NET Core 3

Created on 17 Oct 2019  路  11Comments  路  Source: dotnet/efcore

Entity Framework SQL logs stop showing up in debug after I migrated from .NET Core 2.2 to .NET Core 3.0.

Steps to reproduce

By using this configuration:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "System": "Information",
      "Microsoft": "Information"
    }
  }
}

in appsettings.json I was able to see logging informations about SQL queries made via Entity Framework.

Now, even with this configuration:

{
  "Logging": {
    "LogLevel": {
      "Default": "Debug"
    }
  }
}

I'm unable to see any logging regarding SQL queries made (but I see other debugging messages from .NET Core which suggests that the configurations are picked up correctly).

Did anything change with regards to logging that was not documented here?

Further technical details

EF Core version:
Database provider: Pomelo.EntityFrameworkCore.MySql 2.2.0
Target framework: .NET Core 3.0
Operating system: Mac OS X 10.13.6
IDE: [Non applicable]

closed-external customer-reported

Most helpful comment

@shoe-diamente You cannot use the 2.2 Pomelo provider with EF Core 3.0

All 11 comments

@shoe-diamente From the EF Core side, we accidentally changed the log level for CommandExecuting and CommandExecuted--see #18203. This is fixed for the 3.1 release.

If you're seeing something different, then please post a small, runnable project/solution that demonstrates the behavior you are seeing.

@shoe-diamente You cannot use the 2.2 Pomelo provider with EF Core 3.0

@ErikEJ Thanks! Missed that.

@ErikEJ Technically you can use 2.2.6 with EF Core 3.0 :) (I was using 2.2.0 though).

@shoe-diamente You can use it with .NET Core 3.0. Not with EF Core 3.0.

Oh right, sorry. Misread.

I've updated to .NET Core 3.1 and also the Pomelo Package to 3.1.1 (which says supports 3.1). I still can't see any kind of logging from EF Core.

My logging configuration is:

  "Logging": {
    "LogLevel": {
      "Default": "Debug"
  },

in my聽Startup.cs file I have this:

```c#
// Logging
// Reference: https://stackoverflow.com/a/55947577/10042350
services.AddLogging(opt =>
{
opt.AddConsole(c =>
{
// @todo: Specify UTC
// Reference: https://github.com/dotnet/extensions/issues/1808
c.TimestampFormat = "[HH:mm:ss] ";
});
});

just to add timestamps.

And my database context is correctly added via `AddDbContext`:

```c#
services.AddDbContext<MainContext>();

What am I doing wrong?

@shoe-diamente Please attach a small, runnable project or post a complete code listing that reproduces the behavior you are seeing so that we can investigate.

@ajcvickers

This is a minimal reproducible project: toremove.zip

It uses docker-compose to easily setup the database, so in theory you can reproduce the problem via:

docker-compose up -d
dotnet run

and then making a request to /test via:

curl -v http://localhost:5000/test

and looking at the logs in the main dotnet process. You won't find any log about the SQL query that was made.

Yes, perfect. Thanks :)

Was this page helpful?
0 / 5 - 0 ratings