Exemple #1
0
        public static void Main(string[] args)
        {
            var host = CreateWebHostBuilder(args).Build();

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .WriteTo.Seq("http://localhost:5341")
                         .CreateLogger();
            using (var scope = host.Services.CreateScope())
            {
                var service       = scope.ServiceProvider;
                var loggerFactory = service.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = service.GetRequiredService <BlogContext>();
                    BlogContextSeed.SeedAsync(context, loggerFactory).Wait();
                }
                catch (Exception e)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(e, "SeedAsync 失败");
                }
            }
            host.Run();
        }
Exemple #2
0
        public static void Main(string[] args)
        {
            // Serilog config
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .WriteTo.File(Path.Combine("logs", @"log.txt"), rollingInterval: RollingInterval.Hour)
                         .CreateLogger();

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

            using (var scope = host.Services.CreateScope())
            {
                var services      = scope.ServiceProvider;
                var loggerFactory = services.GetRequiredService <ILoggerFactory>();
                try
                {
                    var context = services.GetRequiredService <BlogContext>();
                    BlogContextSeed.SeedAsync(context, loggerFactory).Wait();
                }
                catch (Exception ex)
                {
                    var logger = loggerFactory.CreateLogger <Program>();
                    logger.LogError(ex, "Error occured seeding the database.");
                }
            }
            host.Run();
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var host = BuildWebHost(args);

            BlogContextSeed.EnsureSeedData(host.Services);

            host.Run();
        }