Beispiel #1
0
        public static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Error().
                         WriteTo.File("./Log/log-.txt", rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            var host = CreateWebHostBuilder(args).Build();

            using (var scope = host.Services.CreateScope())
            {
                var services = scope.ServiceProvider;
                try
                {
                    var context = services.GetRequiredService <DataContext>();
                    var config  = services.GetRequiredService <IConfiguration>();
                    DbInitial.Initial(context, config);
                }
                catch (Exception ex)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(ex, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }
Beispiel #2
0
        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.GetService <AppDbContext>();

                    DbInitial.Seeder(context);
                }
                catch (Exception exception)
                {
                    var logger = services.GetRequiredService <ILogger <Program> >();
                    logger.LogError(exception, "An error occurred while seeding the database.");
                }
            }
            host.Run();
        }