- Install Microsoft.Extensions.Logging.Debug package
- Add for DbContextOptions: .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddDebug()))
- Turn on Sensitive data for DbContextOptions: .EnableSensitiveDataLogging()
For those using Entity Framework Core, if you want to view the output SQL with sensitive data(parameter values) in the Visual Studio output window you may need to use Microsoft.Extensions.Logging.Debug package. This package allows you to turn on debug logging. You just need to add ‘.UseLoggerFactory(LoggerFactory.Create(builder => builder.AddDebug()))’ in place where DbContextOptions is defined. And using the ‘EnableSensitiveDataLogging’ you will turn on sensitive output.
Add UseLoggerFactory and EnableSensistiveDataLogging()
Here is a code snippet with DbContextOptions configuration. Pay attention to the lines 9 and 12.
Window Output Example
Watch my Video for more details
Used packages and Artifacts
- Microsoft.Entityframeworkcore 6.0.8
- Microsoft.Extensions.Logging.Debug 6.0.0
- Visual Studio 2022