diff --git a/EssentialCSharp.Web/Program.cs b/EssentialCSharp.Web/Program.cs index f5c980ad..0b2021af 100644 --- a/EssentialCSharp.Web/Program.cs +++ b/EssentialCSharp.Web/Program.cs @@ -140,13 +140,6 @@ private static void Main(string[] args) ConfigurationManager configuration = builder.Configuration; string connectionString = builder.Configuration.GetConnectionString("EssentialCSharpWebContextConnection") ?? throw new InvalidOperationException("Connection string 'EssentialCSharpWebContextConnection' not found."); - // Create a logger that's accessible throughout the entire method - var loggerFactory = LoggerFactory.Create(loggingBuilder => - loggingBuilder.AddConsole().SetMinimumLevel(LogLevel.Information)); - var initialLogger = loggerFactory.CreateLogger(); - if (profilerSkippedUnsupportedPlatform) - LogSkippingUnsupportedAzureMonitorProfiler(initialLogger, RuntimeInformation.OSDescription); - builder.Services.AddDbContext(options => options.UseSqlServer(connectionString, sql => sql.EnableRetryOnFailure(5))); // Must be registered before AddDataProtection(): hosted services start in registration @@ -441,10 +434,13 @@ await context.HttpContext.Response.WriteAsync( }); } - loggerFactory.Dispose(); - WebApplication app = builder.Build(); + if (profilerSkippedUnsupportedPlatform) + LogSkippingUnsupportedAzureMonitorProfiler( + app.Services.GetRequiredService>(), + RuntimeInformation.OSDescription); + // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) {