上效果图
来看一下操作流程:
一、分为.net Core 2.2 和 .net Core 3.0及以上
(一)、.net Core 2.2
1、在 EntityFrameworkCore中安装Nuget报: Microsoft.Extensions.Logging.Console
2、在XXXXEntityFrameworkModule增加
public static readonly LoggerFactory MyLoggerFactory
= new LoggerFactory(new[]
{
new ConsoleLoggerProvider((category, level)
=> category == DbLoggerCategory.Database.Command.Name
&& level == LogLevel.Information, true)
});
Configuration.Modules.AbpEfCore().AddDbContext<YTMyprocteDbContext>(options =>
{
if (options.ExistingConnection != null)
{
YTMyprocteDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
}
else
{
YTMyprocteDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
}
options.DbContextOptions.UseLoggerFactory(MyLoggerFactory);
options.DbContextOptions.EnableSensitiveDataLogging(true); //logging 不加密 development使用 !
});
(二)、.net Core 3.0及以上
1、在XXXXEntityFrameworkModule增加
public static readonly ILoggerFactory MyLoggerFactory
= LoggerFactory.Create(builder => { builder.AddConsole(); });
if (!SkipDbContextRegistration)
{
Configuration.Modules.AbpEfCore().AddDbContext<SCMDbContext>(options =>
{
if (options.ExistingConnection != null)
{
SCMDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
}
else
{
SCMDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
}
options.DbContextOptions.UseLoggerFactory(MyLoggerFactory);
});
}