Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions EssentialCSharp.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Program>();
if (profilerSkippedUnsupportedPlatform)
LogSkippingUnsupportedAzureMonitorProfiler(initialLogger, RuntimeInformation.OSDescription);

builder.Services.AddDbContext<EssentialCSharpWebContext>(options => options.UseSqlServer(connectionString, sql => sql.EnableRetryOnFailure(5)));

// Must be registered before AddDataProtection(): hosted services start in registration
Expand Down Expand Up @@ -441,10 +434,13 @@ await context.HttpContext.Response.WriteAsync(
});
}

loggerFactory.Dispose();

WebApplication app = builder.Build();

if (profilerSkippedUnsupportedPlatform)
LogSkippingUnsupportedAzureMonitorProfiler(
app.Services.GetRequiredService<ILogger<Program>>(),
RuntimeInformation.OSDescription);

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
Expand Down
Loading