我在配置我的数据库上下文文件时使用了loggingfactory,在示例练习中他们使用了consoleloggingprovider但是在我的练习中它说我找不到名称或类型,并且在示例练习中没有引用到consolelogginprovider我已检查所有导入,这不是问题。这是我的代码,但它确实不是代码问题,我不知道它可能是什么。
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var loggerFactory = new LoggerFactory(providers: new[]
{
new ConsoleLoggerProvider((category, level)
=> category == DbLoggerCategory.Database.Command.Name
&& level == LogLevel.Information, true)
});
if (!optionsBuilder.IsConfigured) //only configure the connection if the parameterless contructor was used (no options where provided).
{
optionsBuilder.UseSqlServer(ConfigurationManager.ConnectionStrings["LotteryConnectionString"].ConnectionString);
//TODO: tell EF (Entity Framework) that is going to operate against a SQL Server database using the connection string in the app.config of the UI project
}
}
这可以在Nuget包中搜索Visual Studio包管理器中的Microsoft.Extensions.Logging.Console,或者下载它here。