AppDbContext 配置
string? connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); //Configuration.GetConnectionString("DefaultConnection"); SqlHelper.ConnectionString = connectionString; SqlHelper.ConnectionStringForERP = builder.Configuration.GetConnectionString("ERPConnection"); builder.Services.AddDbContext<AppDbContext>(options => { options.UseSqlServer(connectionString); //调试 options.EnableSensitiveDataLogging(true);//启用敏感数据记录 //记录日志,包含生成的sql options.LogTo(msg => { //调试-窗口消息 System.Diagnostics.Debug.WriteLine(msg); //输出-窗口消息 Console.WriteLine(msg); }); //记录日志,只查看info类型的日志 //optionsBuilder.LogTo( // msg=> System.Diagnostics.Debug.WriteLine(msg), // LogLevel.Information, // DbContextLoggerOptions.DefaultWithLocalTime); });