using Serilog; using Serilog.Events; var builder = WebApplication.CreateBuilder(args); builder.Host.UseSerilog(); // Add services to the container. builder.Services.AddLogging(c => { c.ClearProviders(); c.AddSerilog(new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Information) .Enrich.FromLogContext() .WriteTo.Console() .WriteTo.Seq("http://log:5341") .CreateLogger()); }); builder.Services.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); try { var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseSerilogRequestLogging(); app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); Log.Information("Starting web host"); app.Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); } finally { Log.CloseAndFlush(); }