Beispiel #1
0
        public static IHost CreateHost(
            Action <ContainerBuilder> containerOverrides  = null,
            Action <IServiceCollection> servicesOverrides = null)
        {
            var serviceProviderFactory = new AppServiceProviderFactory(containerOverrides, servicesOverrides);

            Log.Logger = LoggingHelper.CreateLogger();

            var hostBuilder = new HostBuilder()
                              .UseSerilog((hostingContext, loggerConfiguration) => {
                loggerConfiguration
                .ReadFrom.Configuration(hostingContext.Configuration)
                .Enrich.FromLogContext()
                .Enrich.WithProperty("ApplicationName", "ApiTemplate")
                .Enrich.WithProperty("Environment", hostingContext.HostingEnvironment);

#if DEBUG
                // Used to filter out potentially bad data due to debugging.
                // Very useful when doing Seq dashboards and want to remove logs under debugging session.
                loggerConfiguration.Enrich.WithProperty("DebuggerAttached", Debugger.IsAttached);
#endif
            })
                              .UseServiceProviderFactory(serviceProviderFactory)
                              .ConfigureWebHostDefaults(webHost =>
            {
                webHost
                //.ConfigureLogging(builder => builder.AddSeq())
                .UseTestServer()
                .UseConfiguration(Configuration)
                .UseEnvironment(EnvironmentName)
                .UseStartup <Startup>();
            });

            return(hostBuilder.Start());
        }
Beispiel #2
0
        public static int Main(string[] args)
        {
            Log.Logger = LoggingHelper.CreateLogger();

            try
            {
                Log.Information("Starting host");

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

                host.Run();

                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Application start-up failed");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }