How to log sql queries executed on MySQL that are issued from Pomelo in ASP .Net Core

367 Views Asked by At

Environment Versions:

  • ASP .Net Core 3.1
  • Pomelo.EntityFrameworkCore.MySql 3.1.0

I would like to check executed sql queries on MySQL that are issued from Pomelo in ASP .Net Core project.

The logs should be displayed in Output pane in Visual Studio 2022. But I can't see sql related logs on that pane.


What I already have done are:

  • Adding options.EnableSensitiveDataLogging(); in services.AddDbContextPool in ConfigureServices method.

  • appsettings.Development.json Updated like the below.

    "Logging": { "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information", "Microsoft.EntityFrameworkCore": "Information", "Microsoft.EntityFrameworkCore.Database.Command": "Debug" } }


I refered to these articles:

1

There are 1 best solutions below

0
Nikhil Bansal On

Make sure that have added a constructor to your DBContext which accepts DbContextOptions as parameter.

You can refer to this: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1027#issuecomment-586323865