using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using PSTW_CentralSystem.CustomPolicy; using PSTW_CentralSystem.DBContext; using PSTW_CentralSystem.Models; using Serilog; internal class Program { private static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); // Add services to the container. builder.Services.AddControllersWithViews(); builder.Services.AddRazorPages(); Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(builder.Configuration) .Enrich.FromLogContext() .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Information) .WriteTo.File("Logs/info-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}")) .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Warning) .WriteTo.File("Logs/warning-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}")) .WriteTo.Logger(l => l.Filter.ByIncludingOnly(e => e.Level == Serilog.Events.LogEventLevel.Error) .WriteTo.File("Logs/error-.txt", rollingInterval: RollingInterval.Day, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}")) .WriteTo.Console() .CreateLogger(); builder.Logging.AddSerilog(); builder.Services.AddDbContext(options => { options.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 39)), mysqlOptions => mysqlOptions.CommandTimeout(120) ); }); //builder.Services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores(); builder.Services.AddIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores() .AddDefaultUI() .AddDefaultTokenProviders(); builder.Services.AddAuthorizationCore(options => { options.AddPolicy("RoleModulePolicy", policy => policy.Requirements.Add(new RoleModulePolicy())); }); // Add scope builder.Services.AddScoped(); var app = builder.Build(); // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); app.UseAuthorization(); app.MapRazorPages(); app.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); app.Run(); } }