ABP .net Core 将日志打印在控制台

上效果图

ABP .net Core 将日志打印在控制台
来看一下操作流程:

一、分为.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);
      });
}
上一篇:Abp如何做到 对象的映射


下一篇:基于ABP做一个简单的系统——实战篇:1.项目准备