using Diary.Data; using Diary.Installers; using Diary.Shared; using Serilog; using Serilog.Events; using System.Reflection; /* * Settings - Done * Logging - Done * Database - Done * Automapper - Done * Cors * Views * Swagger - Done * Auth * Exception Middleware - Done * Validation Filter - Done * */ //+Setup Logger Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System", LogEventLevel.Warning) .WriteTo.Console() .WriteTo.Seq("http://seq.lan:5341", apiKey: "Jtfj82GQmcKTAh1kW3zI") .WriteTo.File("Logs/Log.txt") .Enrich.FromLogContext() .CreateLogger(); Log.Information("Starting up"); var builder = WebApplication.CreateBuilder(args); //---Y //Add Serilog builder.Host.UseSerilog(Log.Logger); builder.Services.AddSingleton(new LoggingStartService(Log.Logger, Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().ManifestModule.ScopeName))); //---Y //Database builder.Services.AddDatabase(builder.Configuration); builder.Services.AddScoped(); //---y //Dependancies builder.Services.AddDependencies(); //---Y //Automapper builder.Services.AddAutoMapper(Assembly.GetExecutingAssembly()); builder.Services.AddControllers(); builder.Services.AddExceptionsMiddleware(); builder.Services.AddFilters(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); //---R //+Build var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(opt => { opt.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); opt.RoutePrefix = String.Empty; } ); } app.UseSerilogRequestLogging(); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); app.UseMiddleware(); try { app.Run(); } catch (Exception ex) { Log.Fatal(ex, "Unhandled exception"); } finally { Log.Information("Shut down complete"); Log.CloseAndFlush(); }