Suppress EF core 3.0.x initialized msg

给你一囗甜甜゛ 提交于 2019-12-11 12:25:18

问题


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:


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.



来源:https://stackoverflow.com/questions/56419481/suppress-ef-core-3-0-x-initialized-msg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!