Esempio n. 1
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            startupException = Configuration["STARTUP_EXCEPTION"];

            ExceptionProbe.ThrowIf(startupException, "Startup");
        }
Esempio n. 2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            Log.Debug("----- Begin configuring services.");

            services.AddControllers();

            services.AddApplicationInsightsTelemetry(Configuration);
            services.AddApplicationInsightsKubernetesEnricher();

            ExceptionProbe.ThrowIf(startupException, "ConfigureServices");

            Log.Debug("----- End configuring services.");
        }
Esempio n. 3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            Log.Debug("----- Begin configuring pipeline.");

            var pathBase = Configuration["PATH_BASE"];

            if (!string.IsNullOrWhiteSpace(pathBase))
            {
                app.UsePathBase(pathBase);
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.MapWhen(context =>
                        context.Request.Path.Value.StartsWith("/hc/"),
                        ab => ab.Use(async(context, next) =>
            {
                await context.Response.WriteAsync("OK.");
            })
                        );

            app.UseSerilogRequestLogging();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            ExceptionProbe.ThrowIf(startupException, "Configure");

            Log.Debug("----- End configuring pipeline.");
        }
Esempio n. 4
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            var startupException = Environment.GetEnvironmentVariable("STARTUP_EXCEPTION");

            var builder = Host.CreateDefaultBuilder(args)
                          .UseSerilog((context, services, loggerConfiguration) =>
            {
                Log.Debug("----- Configuring logging...");

                loggerConfiguration
                .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                .Enrich.WithProperty("HostName", HostName)
                .Enrich.WithProperty("ApplicationContext", AppName)
                .WriteTo.Seq(Environment.GetEnvironmentVariable("SEQ_URL") ?? "http://localhost:5341");

                ExceptionProbe.ThrowIf(startupException, "CreateHostBuilder.UseSerilog");

                Log.Debug("----- Closing startup logger ({ApplicationContext})...", AppName);
                Log.CloseAndFlush();
            },
                                      writeToProviders: true)
                          .ConfigureWebHostDefaults(webBuilder =>
            {
                Log.Debug("----- Configuring WebHost defaults...");

                webBuilder
                .UseStartup <Startup>()
                .CaptureStartupErrors(false);

                ExceptionProbe.ThrowIf(startupException, "CreateHostBuilder.ConfigureWebHostDefaults");
            });

            ExceptionProbe.ThrowIf(startupException, "CreateHostBuilder");

            return(builder);
        }