public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .ConfigureAppConfiguration((hostingContext, config) => { var env = hostingContext.HostingEnvironment; config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); config.AddEnvironmentVariables(); }) .UseSerilog((hostingContext, loggerConfiguration) => { loggerConfiguration .ReadFrom.Configuration(hostingContext.Configuration) .Enrich.FromLogContext(); string splunkCollectorUrl = hostingContext.Configuration["SPLUNK_COLLECTOR_URL"]; string splunkToken = hostingContext.Configuration["SPLUNK_TOKEN"]; if (!string.IsNullOrEmpty(splunkCollectorUrl) && !string.IsNullOrEmpty(splunkToken)) { // enable Splunk logger using Serilog var fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(hostingContext.Configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", hostingContext.Configuration["SPLUNK_CHANNEL"])); } loggerConfiguration.WriteTo.EventCollector( splunkCollectorUrl, splunkToken, sourceType: "manual", restrictedToMinimumLevel: LogEventLevel.Information, messageHandler: new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true } ); } }) .UseStartup <Startup>();
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, IMemoryCache cache) { // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(_configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(_configuration["SPLUNK_TOKEN"]) ) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(_configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", _configuration["SPLUNK_CHANNEL"])); } var splunkUri = new Uri(_configuration["SPLUNK_COLLECTOR_URL"]); var upperSplunkHost = splunkUri.Host?.ToUpperInvariant() ?? string.Empty; // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: _configuration["SPLUNK_COLLECTOR_URL"], sourceType: "manual", eventCollectorToken: _configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("Onestop-Service Container Starting"); // OneStop does not seem to set the SoapAction properly app.Use(async(context, next) => { if (context.Request.Path.Value.Equals("/receiveFromHub")) { string soapAction = context.Request.Headers["SOAPAction"]; if (string.IsNullOrEmpty(soapAction) || soapAction.Equals("\"\"")) { context.Request.Headers["SOAPAction"] = "http://tempuri.org/IReceiveFromHubService/receiveFromHub"; } } await next(); }); // , serializer: SoapSerializer.XmlSerializer, caseInsensitivePath: true if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } bool startHangfire = true; #if DEBUG // do not start Hangfire if we are running tests. foreach (var assem in Assembly.GetEntryAssembly().GetReferencedAssemblies()) { if (assem.FullName.ToLowerInvariant().StartsWith("xunit")) { startHangfire = false; break; } } #endif if (startHangfire) { // enable Hangfire, using the default authentication model (local connections only) app.UseHangfireServer(); DashboardOptions dashboardOptions = new DashboardOptions { AppPath = null }; app.UseHangfireDashboard("/hangfire", dashboardOptions); } if (!string.IsNullOrEmpty(_configuration["ENABLE_HANGFIRE_JOBS"])) { SetupHangfireJobs(app, cache); } app.UseAuthentication(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "JAG LCRB One Stop Service"); }); app.UseHealthChecks("/hc", new HealthCheckOptions { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); // by positioning this after the health check, no need to filter out health checks from request logging. app.UseSerilogRequestLogging(); app.UseMvc(); app.UseSoapEndpoint <IReceiveFromHubService>(path: "/receiveFromHub", binding: new BasicHttpBinding()); // tell the soap service about the cache. using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { var memoryCache = serviceScope.ServiceProvider.GetService <IMemoryCache>(); var soap = serviceScope.ServiceProvider.GetService <IReceiveFromHubService>(); soap.SetCache(memoryCache); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { var log = loggerFactory.CreateLogger("Startup"); string pathBase = Configuration["BASE_PATH"]; if (!string.IsNullOrEmpty(pathBase)) { app.UsePathBase(pathBase); } if (!env.IsProduction()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } app.Use(async(ctx, next) => { ctx.Response.Headers.Add("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload"); await next(); }); // X-Content-Type-Options header app.UseXContentTypeOptions(); // Referrer-Policy header. app.UseReferrerPolicy(opts => opts.NoReferrer()); // X-Xss-Protection header app.UseXXssProtection(options => options.EnabledWithBlockMode()); // X-Frame-Options header app.UseXfo(options => options.Deny()); if (!env.IsDevelopment()) // when running locally we can't have a strict CSP { // Content-Security-Policy header app.UseCsp(opts => { opts .BlockAllMixedContent() .StyleSources(s => s.Self().UnsafeInline().CustomSources("https://use.fontawesome.com", "https://stackpath.bootstrapcdn.com")) .FontSources(s => s.Self().CustomSources("https://use.fontawesome.com")) .FormActions(s => s.Self()) .FrameAncestors(s => s.Self()) .ImageSources(s => s.Self()) .DefaultSources(s => s.Self()) .ScriptSources(s => s.Self().CustomSources("https://apis.google.com", "https://maxcdn.bootstrapcdn.com", "https://cdnjs.cloudflare.com", "https://code.jquery.com", "https://stackpath.bootstrapcdn.com", "https://fonts.googleapis.com")); }); } StaticFileOptions staticFileOptions = new StaticFileOptions() { OnPrepareResponse = ctx => { ctx.Context.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, private"; ctx.Context.Response.Headers[HeaderNames.Pragma] = "no-cache"; ctx.Context.Response.Headers["X-Frame-Options"] = "SAMEORIGIN"; ctx.Context.Response.Headers["X-XSS-Protection"] = "1; mode=block"; ctx.Context.Response.Headers["X-Content-Type-Options"] = "nosniff"; } }; app.UseStaticFiles(staticFileOptions); app.UseSpaStaticFiles(staticFileOptions); app.UseNoCacheHttpHeaders(); // IMPORTANT: This session call MUST go before UseMvc() app.UseSession(); app.UseAuthentication(); // set the cookie policy app.UseCookiePolicy(new CookiePolicyOptions { HttpOnly = HttpOnlyPolicy.Always, Secure = CookieSecurePolicy.Always, MinimumSameSitePolicy = Microsoft.AspNetCore.Http.SameSiteMode.None }); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; // Only run the angular CLI Server in Development mode (not staging or test.) if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(Configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(Configuration["SPLUNK_TOKEN"])) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(Configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", Configuration["SPLUNK_CHANNEL"])); } var splunkUri = new Uri(Configuration["SPLUNK_COLLECTOR_URL"]); var upperSplunkHost = splunkUri.Host?.ToUpperInvariant() ?? string.Empty; // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: Configuration["SPLUNK_COLLECTOR_URL"], sourceType: "manual", eventCollectorToken: Configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("Pill Press Portal Container Started"); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { var log = loggerFactory.CreateLogger("Startup"); string connectionString = "unknown."; #if (USE_MSSQL) if (!string.IsNullOrEmpty(Configuration["DB_PASSWORD"])) { try { using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { log.LogDebug("Fetching the application's database context ..."); AppDbContext context = serviceScope.ServiceProvider.GetService <AppDbContext>(); IDynamicsClient dynamicsClient = serviceScope.ServiceProvider.GetService <IDynamicsClient>(); connectionString = context.Database.GetDbConnection().ConnectionString; log.LogDebug("Migrating the database ..."); context.Database.Migrate(); log.LogDebug("The database migration complete."); // run the database seeders log.LogDebug("Adding/Updating seed data ..."); Seeders.SeedFactory <AppDbContext> seederFactory = new Seeders.SeedFactory <AppDbContext>(Configuration, env, loggerFactory, dynamicsClient); seederFactory.Seed((AppDbContext)context); log.LogDebug("Seeding operations are complete."); } } catch (Exception e) { StringBuilder msg = new StringBuilder(); msg.AppendLine("The database migration failed!"); msg.AppendLine("The database may not be available and the application will not function as expected."); msg.AppendLine("Please ensure a database is available and the connection string is correct."); msg.AppendLine("If you are running in a development environment, ensure your test database and server configuration match the project's default connection string."); msg.AppendLine("Which is: " + connectionString); log.LogCritical(new EventId(-1, "Database Migration Failed"), e, msg.ToString()); } } #else // seed for newsletter. using (IServiceScope serviceScope = app.ApplicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope()) { log.LogDebug("Fetching the application's MS Dynamics interface ..."); IDynamicsClient dynamicsClient = serviceScope.ServiceProvider.GetService <IDynamicsClient>(); // run the database seeders log.LogDebug("Adding/Updating seed data ..."); Seeders.SeedFactory <AppDbContext> seederFactory = new Seeders.SeedFactory <AppDbContext>(_configuration, env, loggerFactory, dynamicsClient); seederFactory.Seed(null); log.LogDebug("Seeding operations are complete."); } #endif string pathBase = _configuration["BASE_PATH"]; if (!string.IsNullOrEmpty(pathBase)) { app.UsePathBase(pathBase); } if (!env.IsProduction()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler(errorApp => { errorApp.Run(async context => { context.Response.StatusCode = 500; context.Response.ContentType = "text/html"; await context.Response.WriteAsync("An unexpected server error occurred.\r\n"); var exceptionHandlerPathFeature = context.Features.Get <IExceptionHandlerPathFeature>(); if (exceptionHandlerPathFeature?.Error != null) { Log.Logger.Error(exceptionHandlerPathFeature?.Error, "Unexpected Error"); } }); }); app.UseHsts(); // Strict-Transport-Security app.UseCors(MyAllowSpecificOrigins); } var healthCheckOptions = new HealthCheckOptions { ResponseWriter = async(c, r) => { c.Response.ContentType = MediaTypeNames.Application.Json; var result = JsonConvert.SerializeObject( new { checks = r.Entries.Select(e => new { description = e.Key, status = e.Value.Status.ToString(), responseTime = e.Value.Duration.TotalMilliseconds }), totalResponseTime = r.TotalDuration.TotalMilliseconds }); await c.Response.WriteAsync(result); } }; app.UseHealthChecks("/hc/ready", new HealthCheckOptions { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); app.UseHealthChecks("/hc/live", new HealthCheckOptions { // Exclude all checks and return a 200-Ok. Predicate = (_) => false }); app.UseXContentTypeOptions(); app.UseXfo(xfo => xfo.Deny()); StaticFileOptions staticFileOptions = new StaticFileOptions(); staticFileOptions.OnPrepareResponse = ctx => { ctx.Context.Response.Headers[HeaderNames.CacheControl] = "no-cache, no-store, must-revalidate, private"; ctx.Context.Response.Headers[HeaderNames.Pragma] = "no-cache"; ctx.Context.Response.Headers["X-Frame-Options"] = "SAMEORIGIN"; ctx.Context.Response.Headers["X-XSS-Protection"] = "1; mode=block"; ctx.Context.Response.Headers["X-Content-Type-Options"] = "nosniff"; }; app.UseStaticFiles(staticFileOptions); app.UseSpaStaticFiles(staticFileOptions); app.UseXXssProtection(options => options.EnabledWithBlockMode()); app.UseNoCacheHttpHeaders(); // IMPORTANT: This session call MUST go before UseMvc() app.UseSession(); app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller}/{action=Index}/{id?}"); }); // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(_configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(_configuration["SPLUNK_TOKEN"]) ) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(_configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", _configuration["SPLUNK_CHANNEL"])); } var splunkUri = new Uri(_configuration["SPLUNK_COLLECTOR_URL"]); var upperSplunkHost = splunkUri.Host?.ToUpperInvariant() ?? string.Empty; // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: _configuration["SPLUNK_COLLECTOR_URL"], sourceType: "manual", eventCollectorToken: _configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("CARLA Portal Container Started"); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } if (env.IsDevelopment()) { app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; // Only run the angular CLI Server in Development mode (not staging or test.) if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); } else { Log.Logger.Information("Not enabling single page application hosting from Dotnet - using externally hosted static content."); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { string basePath = _configuration["BASE_PATH"]; if (!string.IsNullOrEmpty(basePath)) { app.UsePathBase(basePath); } 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.UseStaticFiles(); if (!env.IsDevelopment()) { app.UseSpaStaticFiles(); } // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(_configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(_configuration["SPLUNK_TOKEN"]) ) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(_configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", _configuration["SPLUNK_CHANNEL"])); } var splunkUri = new Uri(_configuration["SPLUNK_COLLECTOR_URL"]); var upperSplunkHost = splunkUri.Host?.ToUpperInvariant() ?? string.Empty; // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: _configuration["SPLUNK_COLLECTOR_URL"], sourceType: "manual", eventCollectorToken: _configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("CSA Portal Container Started"); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller}/{action=Index}/{id?}"); }); app.UseSpa(spa => { // To learn more about options for serving an Angular SPA from ASP.NET Core, // see https://go.microsoft.com/fwlink/?linkid=864501 spa.Options.SourcePath = "ClientApp"; if (env.IsDevelopment()) { spa.UseAngularCliServer(npmScript: "start"); } }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(Configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(Configuration["SPLUNK_TOKEN"]) ) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(Configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", Configuration["SPLUNK_CHANNEL"])); } // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: Configuration["SPLUNK_COLLECTOR_URL"], sourceType: "onestop", eventCollectorToken: Configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("LDB-Orders-Service Container Starting"); bool startHangfire = true; #if DEBUG // do not start Hangfire if we are running tests. foreach (var assem in Assembly.GetEntryAssembly().GetReferencedAssemblies()) { if (assem.FullName.ToLowerInvariant().StartsWith("xunit")) { startHangfire = false; break; } } #endif if (startHangfire) { // enable Hangfire, using the default authentication model (local connections only) app.UseHangfireServer(); DashboardOptions dashboardOptions = new DashboardOptions { AppPath = null }; app.UseHangfireDashboard("/hangfire", dashboardOptions); } if (!string.IsNullOrEmpty(Configuration["ENABLE_HANGFIRE_JOBS"])) { SetupHangfireJobs(app); } app.UseAuthentication(); app.UseHealthChecks("/hc", new HealthCheckOptions { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); // by positioning this after the health check, no need to filter out health checks from request logging. app.UseSerilogRequestLogging(); app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseHealthChecks("/hc/ready", new HealthCheckOptions { Predicate = _ => true, ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse }); app.UseHealthChecks("/hc/live", new HealthCheckOptions { // Exclude all checks and return a 200-Ok. Predicate = (_) => false }); app.UseEndpoints(endpoints => { endpoints.MapGrpcService <FileManagerService>(); endpoints.MapGet("/", async context => { await context.Response.WriteAsync("Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909"); }); }); // enable Splunk logger using Serilog if (!string.IsNullOrEmpty(Configuration["SPLUNK_COLLECTOR_URL"]) && !string.IsNullOrEmpty(Configuration["SPLUNK_TOKEN"]) ) { Serilog.Sinks.Splunk.CustomFields fields = new Serilog.Sinks.Splunk.CustomFields(); if (!string.IsNullOrEmpty(Configuration["SPLUNK_CHANNEL"])) { fields.CustomFieldList.Add(new Serilog.Sinks.Splunk.CustomField("channel", Configuration["SPLUNK_CHANNEL"])); } var splunkUri = new Uri(Configuration["SPLUNK_COLLECTOR_URL"]); var upperSplunkHost = splunkUri.Host?.ToUpperInvariant() ?? string.Empty; // Fix for bad SSL issues Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .WriteTo.EventCollector(splunkHost: Configuration["SPLUNK_COLLECTOR_URL"], sourceType: "filemanagerservice", eventCollectorToken: Configuration["SPLUNK_TOKEN"], restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, #pragma warning disable CA2000 // Dispose objects before losing scope messageHandler: new HttpClientHandler() { ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => { return(true); } } #pragma warning restore CA2000 // Dispose objects before losing scope ) .CreateLogger(); Serilog.Debugging.SelfLog.Enable(Console.Error); Log.Logger.Information("File Manager Service Container Started"); } else { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.WithExceptionDetails() .WriteTo.Console() .CreateLogger(); } }