public static void Main(string[] args) { var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <ApplicationDbContext>(); var dpContext = services.GetRequiredService <DataProtectionKeysContext>(); var functionalSvc = services.GetRequiredService <IFunctionalSvc>(); var countrySvc = services.GetRequiredService <ICountrySvc>(); DbContextInitializer.Initialize(dpContext, context, functionalSvc, countrySvc).Wait(); } catch (Exception ex) { Log.Error("An error occured while seeding the database {Error} {StackTrace} {InnerException} {Source}", ex.Message, ex.StackTrace, ex.InnerException, ex.Source); } } host.Run(); }
public static void PrepareDatabase(IHost host) { using var scope = host.Services.CreateScope(); var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDataContext>(); DbContextInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } }
public static void Main(string[] args) { var env = new HostingEnvironment { ContentRootPath = Directory.GetCurrentDirectory() }; Log.Logger = new LoggerConfiguration() .MinimumLevel.Error() .MinimumLevel.Override("Microsoft", LogEventLevel.Error) .Enrich.FromLogContext() .Enrich.WithProperty("Application", "CMS_APP") .Enrich.WithProperty("MachineName", Environment.MachineName) .Enrich.WithProperty("CurrentManagedThreadId", Environment.CurrentManagedThreadId) .Enrich.WithProperty("OSVersion", Environment.OSVersion) .Enrich.WithProperty("Version", Environment.Version) .Enrich.WithProperty("UserName", Environment.UserName) .Enrich.WithProperty("ProcessId", Process.GetCurrentProcess().Id) .Enrich.WithProperty("ProcessName", Process.GetCurrentProcess().ProcessName) .WriteTo.File(formatter: new CompactJsonFormatter(), path: Path.Combine(env.ContentRootPath + $"{Path.DirectorySeparatorChar}Logs{Path.DirectorySeparatorChar}", $"load_error_{DateTime.Now:yyyyMMdd}.json")) .CreateLogger(); var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var logger = Log.Logger; var context = services.GetRequiredService <ApplicationDbContext>(); var quartzDbContext = services.GetRequiredService <QuartzDbContext>(); var functional = services.GetRequiredService <IFunctionalService>(); DbContextInitializer.Initialize(context, quartzDbContext, functional, logger).Wait(); } catch (Exception ex) { Log.Error(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <GameItemsContext>(); DbContextInitializer.Initialize(context); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occurred while seeding the database."); } } host.Run(); }
public static void Main(string[] args) { DbContextInitializer.Initialize(); CreateWebHostBuilder(args).Build().Run(); }