efCore3.1+mysql 启用日志查询记录

 1.  Nuget安装 Microsoft.Extensions.Logging

2.      

 /// 
        /// 记录sql语句日志
        /// 
        public static readonly ILoggerFactory MyLoggerFactory
          = LoggerFactory.Create(builder => {

         builder.AddFilter((category, level) =>
             category == DbLoggerCategory.Database.Command.Name
             && level == LogLevel.Information).AddConsole();
         
         });



 //添加日志
            services.AddDbContext(options=>options.UseLoggerFactory(MyLoggerFactory).UseMySql(Configuration.GetConnectionString("conStr")));

 

你可能感兴趣的:(MySql,EFCore)