public static async Task Main(string[] args) { Log.Logger = new LoggerConfiguration() .ReadFrom.Configuration(Configuration) .WriteTo.Debug() .CreateLogger(); Console.WriteLine("Enabling prometheus-net.DotNetStats..."); DotNetRuntimeStatsBuilder.Customize() .WithThreadPoolSchedulingStats() .WithContentionStats() .WithGcStats() .WithJitStats() .WithThreadPoolStats() .WithExceptionStats() .WithErrorHandler(ex => Log.Error(ex, "DotNetRuntime Error")) //.WithDebuggingMetrics(true); .StartCollecting(); try { var host = CreateHostBuilder(args).Build(); if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").Equals("Development") && Configuration.GetValue <bool>("UseInMemoryDatabase") == false) { using var serviceScope = host.Services.CreateScope(); var services = serviceScope.ServiceProvider; using var scope = services.GetRequiredService <IServiceScopeFactory>().CreateScope(); await DbMigrationHelper <ApplicationDbContext> .EnsureDatabaseMigratedAsync(scope); } Log.Information($"web api starting at {DateTime.UtcNow}"); host.Run(); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly"); return; } finally { Log.CloseAndFlush(); } }