public static int Main(string[] args) { DefaultLogger.CreateNlog(null); var logger = DefaultLogger.CreateNlog(null); try { var host = CreateHostBuilder(args).Build(); using (var serviceScope = host.Services.GetRequiredService <IServiceScopeFactory>().CreateScope()) using (var context = serviceScope.ServiceProvider.GetService <AppDbContext>()) { logger.Info("Migrations started ..."); context.Database.Migrate(); logger.Info("Migrations finished."); } host.Run(); } catch (Exception exception) { logger.Error(exception, "Stopped program because of exception"); return(1); } finally { NLog.LogManager.Shutdown(); } return(0); }