为了使用数据库,我使用 ORM Entity Framework Core。启动应用程序后,对数据库的所有请求都会记录在控制台中。我没有安装日志记录。如何禁用它?
程序.cs:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHangfire(x => x.UseSqlServerStorage(builder.Configuration.GetConnectionString("DefaultConnection")));
builder.Services.AddHangfireServer(opt =>
{
opt.StopTimeout = TimeSpan.FromMinutes(5);
});
builder.Services.AddControllers();
builder.Services.AddSwaggerGen();
builder.Services.AddAutoMapper(typeof(AutoMapperConf));
builder.Services.AddCors(o => o.AddDefaultPolicy(builder =>
{
builder
.WithOrigins("http://localhost:80")
.AllowCredentials()
.AllowAnyHeader()
.AllowAnyMethod();
}));
// DB Services
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<AMContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Transient);
builder.Services.AddDbContext<AMIdentityContext>(options => options.UseSqlServer(connectionString), ServiceLifetime.Transient);
builder.Services.ConfigureApplicationCookie(opt =>
{
opt.LoginPath = "/auth/login";
opt.LogoutPath = "/auth/logut";
opt.AccessDeniedPath = "/";
opt.ExpireTimeSpan = TimeSpan.FromDays(180);
});
builder.Services.AddIdentity<DBUser, IdentityRole>(config =>
{
config.Password.RequireNonAlphanumeric = false;
config.Password.RequiredLength = 1;
config.Password.RequireUppercase = false;
config.Password.RequireDigit = false;
config.Password.RequireLowercase = false;
})
.AddEntityFrameworkStores<AMIdentityContext>()
.AddDefaultTokenProviders();
builder.Services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "wwwroot";
});
var app = builder.Build();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseCors();
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseHangfireDashboard("/hangfire", new DashboardOptions
{
Authorization = new[] { new HangfireAuthFilter() }
});
app.MapControllers();
app.UseEndpoints(endpoints =>
{
endpoints.MapDefaultControllerRoute();
});
app.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (app.Environment.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
spa.UseProxyToSpaDevelopmentServer("http://localhost:4200");
}
});
RecurringJob.AddOrUpdate<HangFireTaskManager>("TaskParser", (method) => method.TaskParser(), "*/1 * * * * *");
RecurringJob.AddOrUpdate<HangFireTaskManager>("PostParser", (method) => method.PostParser(), "*/1 * * * * *");
RecurringJob.AddOrUpdate<HangFireTaskManager>("MonitorStatus", (method) => method.MonitorStatus(), "*/1 * * * * *");
RecurringJob.AddOrUpdate<HangFireTaskManager>("CommentParser", (method) => method.CommentParser(), "*/1 * * * * *");
RecurringJob.AddOrUpdate<HangFireTaskManager>("LikesParser", (method) => method.LikesParser(), "*/1 * * * * *");
// Init Roles
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var rolesManager = services.GetRequiredService<RoleManager<IdentityRole>>();
await RoleInitializer.InitializeAsync(rolesManager);
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred while seeding the database.");
}
}
app.Run();