public static void Main(string[] args) { var host = CreateWebHostBuilder(args).Build(); //CreateWebHostBuilder(args).Build().Run(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var context = services.GetRequiredService <AppDbContext>(); AppDbInitializer.InitializeAsync(context, services).Wait(); } catch (Exception ex) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(ex, "An error occured while seeding the database."); } } host.Run(); }
public static async Task Main(string[] args) { var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger(); try { logger.Debug("Main started"); logger.Error("Test error"); var host = CreateHostBuilder(args).Build(); using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; try { var userManager = services.GetRequiredService <UserManager <Profile> >(); var rolesManager = services.GetRequiredService <RoleManager <IdentityRole> >(); var initData = services.GetRequiredService <IAppDbInitData>(); await AppDbInitializer.InitializeAsync(userManager, rolesManager, initData); } catch (Exception ex) { logger.Error(ex, "An error occurred while seeding the database."); } } host.Run(); } catch (Exception exception) { logger.Error(exception, "Stopped program because of exception"); throw; } finally { NLog.LogManager.Shutdown(); } }