Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DbContextOptionsBuilder.EnableSensitiveDataLogging Doesn't Do Anything

I'm trying to track down the cause of an Entity Framework InvalidOperationException in an ASP.NET Core project. The exception suggests using DbContextOptionsBuilder.EnableSensitiveDataLogging.

In my Startup.cs I have:

public void ConfigureServices(IServiceCollection services)
{
    services.AddDbContext<TodoContext>(opt =>
    {
        opt.UseInMemoryDatabase("TodoList");
        opt.EnableSensitiveDataLogging();
    });
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}

The problem is it doesn't seem to do anything. The exception message I get is exactly the same and still suggests using DbContextOptionsBuilder.EnableSensitiveDataLogging.

Am I missing something?

like image 593
Simon Morgan Avatar asked Jan 24 '19 19:01

Simon Morgan


1 Answers

I had the same problem. Solved it by using the OnConfiguring method in the DbContext itself, rather than the ConfigureServices method in Startup.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    optionsBuilder.EnableSensitiveDataLogging();
}

This option is documented here.

like image 141
christian Avatar answered Sep 28 '22 19:09

christian