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

上效果图

ABP .net Core 将日志打印在控制台_第1张图片
来看一下操作流程:

一、分为.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(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(options =>
      {
          if (options.ExistingConnection != null)
          {
              SCMDbContextConfigurer.Configure(options.DbContextOptions, options.ExistingConnection);
          }
          else
          {
              SCMDbContextConfigurer.Configure(options.DbContextOptions, options.ConnectionString);
          }
          options.DbContextOptions.UseLoggerFactory(MyLoggerFactory);
      });
}

你可能感兴趣的:(linux,大数据,sublime,text,logging,md5)