Suppress EF core 3.0.x initialized msg

c# ef-core-3.0 entity-framework-core

Question

I have:

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 
{
  string connectionString = "mydb.db;";
  optionsBuilder
  .UseLoggerFactory(MainWorker.ConsoleLoggerFactory)
  .EnableSensitiveDataLogging(true)
  .UseSqlite(connectionString);
}

Whenever I access my DBContext the console shows

info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 3.0.0-preview4.19176.6 initialized

Is there a way to filter out this particular message ? as I do a lot of queries it just clutters my console debug window ..

1
2
6/3/2019 4:24:32 AM

Accepted Answer

EF Core specific log messages are configured via DbContextOptionsBuilder.ConfigureWarnings method (yeah, the name is a bit misleading).

The EventId of the message in question is CoreEventId.ContextInitialized. And you suppress it using Ignore:

optionsBuilder.ConfigureWarnings(warnings => warnings
    .Ignore(CoreEventId.ContextInitialized));

Of course it can be chained with the other optionsBuilder calls. Also you may want to suppress the second context lifetime related log message with CoreEventId.ContextDisposed.

3
6/3/2019 9:38:57 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow