示例#1
0
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;

            startupException = Configuration["STARTUP_EXCEPTION"];

            ExceptionProbe.ThrowIf(startupException, "Startup");
        }
示例#2
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);

                app.Use((context, next) =>
                {
                    context.Request.PathBase = new PathString($"{pathBase}");
                    return(next());
                });
            }

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            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.MapRazorPages();
            });

            ExceptionProbe.ThrowIf(startupException, "Configure");

            Log.Debug("----- End configuring pipeline.");
        }
示例#3
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.AddRazorPages();

            services.AddHttpClient <WeatherForecastApiClient>(client =>
            {
                client.BaseAddress = new Uri(Configuration["WebApiBaseAddress"]);
            });

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

            ExceptionProbe.ThrowIf(startupException, "ConfigureServices");

            Log.Debug("----- End configuring services.");
        }
示例#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);
        }