private void InitializeDbData(IApplicationBuilder app, IConfiguration configuration) { try { using (var scope = app.ApplicationServices.GetService <IServiceScopeFactory>().CreateScope()) { var repositoryFactory = scope.ServiceProvider.GetRequiredService <IRepositoryFactory>(); SeedDataBase.MigrateDatabase(repositoryFactory); SeedDataBase.SeedDatabase(repositoryFactory); } } catch (Exception ex) { string pathLog = _webRootPath.Replace("wwwroot", "logs"); string pathFile = pathLog + "\\log-InitializeDbData.txt"; if (!Directory.Exists(pathLog)) { Directory.CreateDirectory(pathLog); } if (File.Exists(pathFile)) { File.Delete(pathFile); } File.WriteAllText(pathFile, "InitializeDbData Error: " + ex.Message); } }