public void ApplyMigrations() { long lastMigrationOrder = 0; if (!dbQuery.TableExists(RowDataGatewayHelper.GetTableName(typeof(MigrationHistoryGateway)))) { new AddedMigrationHistoryEntity { DbQuery = dbQuery }.Up(); } else { lastMigrationOrder = GetLastMigrationOrder(); } var migrations = migrationProvider.GetMigrationsAfter(lastMigrationOrder); HandleMigrations(migrations, (migration, type) => { migration.Up(); new MigrationHistoryGateway(dbQuery) { MigrationName = type.Name, MigrationOrder = DbMigrationHelper.GetMigrationOrder(type) }.Save(); }); }
public static async Task Main(string[] args) { var host = CreateHostBuilder(args).Build() .MigrateDatabase <ApplicationDbContext>() .MigrateDatabase <AuditLogDbContext>(); await DbMigrationHelper.EnsureSeedData(host); await host.RunAsync(); }
public static async Task <int> Main(string[] args) { Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.Hosting.Lifetime", LogEventLevel.Information) .MinimumLevel.Override("System", LogEventLevel.Warning) .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information) .Enrich.FromLogContext() // uncomment to write to Azure diagnostics stream //.WriteTo.File( // @"identityserver.txt", // fileSizeLimitBytes: 1_000_000, // rollOnFileSizeLimit: true, // shared: true, // flushToDiskInterval: TimeSpan.FromSeconds(1)) .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Code) .CreateLogger(); try { Log.Information("Starting host..."); "update-ca-certificates".Bash(); var seed = args.Any(x => x == SeedArgs); if (seed) { args = args.Except(new[] { SeedArgs }).ToArray(); } var host = CreateHostBuilder(args).Build(); await DbMigrationHelper.Migrate(host); if (seed) { await DbSeederHelper.Seed(host); } await host.RunAsync(); return(0); } catch (Exception ex) { Log.Fatal(ex, "Host terminated unexpectedly."); return(1); } finally { Log.CloseAndFlush(); } }
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(); } }