禁止EF core 3.0.x初始化味精 [英] Suppress EF core 3.0.x initialized msg

查看:109
本文介绍了禁止EF core 3.0.x初始化味精的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有:

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

每当我访问DBContext时,控制台都会显示

Whenever I access my DBContext the console shows


信息:Microsoft.EntityFrameworkCore.Infrastructure [10403]
Entity Framework Core 3.0.0-preview4.19176.6已初始化

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 ..

推荐答案

EF核心特定的日志消息是通过< a href = https://docs.microsoft.com/zh-cn/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.configurewarnings?view=efcore-2.1 rel = nofollow noreferrer> DbContextOptionsBuilder.ConfigureWarnings 方法(是的,名称有点误导)。

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

相关邮件的 EventId CoreEventId.ContextInitialized 。然后使用忽略来抑制它:

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

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

当然,它可以与其他 optionsBuilder 通话。另外,您可能想使用 CoreEventId.ContextDisposed 取消第二条与上下文生存期相关的日志消息。

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.

这篇关于禁止EF core 3.0.x初始化味精的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆