|
|
@ -1,87 +1,76 @@ |
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
|
using Microsoft.AspNetCore.Diagnostics.HealthChecks; |
|
|
|
using Microsoft.AspNetCore.Hosting; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Microsoft.Extensions.Logging; |
|
|
|
namespace WebStatus; |
|
|
|
|
|
|
|
namespace WebStatus |
|
|
|
public class Startup |
|
|
|
{ |
|
|
|
public class Startup |
|
|
|
public Startup(IConfiguration configuration) |
|
|
|
{ |
|
|
|
public Startup(IConfiguration configuration) |
|
|
|
{ |
|
|
|
Configuration = configuration; |
|
|
|
} |
|
|
|
Configuration = configuration; |
|
|
|
} |
|
|
|
|
|
|
|
public IConfiguration Configuration { get; } |
|
|
|
public IConfiguration Configuration { get; } |
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services) |
|
|
|
{ |
|
|
|
RegisterAppInsights(services); |
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services) |
|
|
|
{ |
|
|
|
RegisterAppInsights(services); |
|
|
|
|
|
|
|
services.AddControllers(); |
|
|
|
services.AddControllers(); |
|
|
|
|
|
|
|
services.AddOptions(); |
|
|
|
services.AddHealthChecks() |
|
|
|
.AddCheck("self", () => HealthCheckResult.Healthy()); |
|
|
|
services.AddOptions(); |
|
|
|
services.AddHealthChecks() |
|
|
|
.AddCheck("self", () => HealthCheckResult.Healthy()); |
|
|
|
|
|
|
|
services |
|
|
|
.AddHealthChecksUI() |
|
|
|
.AddInMemoryStorage(); |
|
|
|
services |
|
|
|
.AddHealthChecksUI() |
|
|
|
.AddInMemoryStorage(); |
|
|
|
|
|
|
|
services.AddMvc() |
|
|
|
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0); |
|
|
|
} |
|
|
|
services.AddMvc() |
|
|
|
.SetCompatibilityVersion(CompatibilityVersion.Version_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, ILoggerFactory loggerFactory) |
|
|
|
{ |
|
|
|
//loggerFactory.AddAzureWebAppDiagnostics();
|
|
|
|
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
|
|
|
// 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) |
|
|
|
{ |
|
|
|
//loggerFactory.AddAzureWebAppDiagnostics();
|
|
|
|
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
|
|
|
|
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
app.UseExceptionHandler("/Home/Error"); |
|
|
|
} |
|
|
|
if (env.IsDevelopment()) |
|
|
|
{ |
|
|
|
app.UseDeveloperExceptionPage(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
app.UseExceptionHandler("/Home/Error"); |
|
|
|
} |
|
|
|
|
|
|
|
var pathBase = Configuration["PATH_BASE"]; |
|
|
|
if (!string.IsNullOrEmpty(pathBase)) |
|
|
|
{ |
|
|
|
app.UsePathBase(pathBase); |
|
|
|
} |
|
|
|
var pathBase = Configuration["PATH_BASE"]; |
|
|
|
if (!string.IsNullOrEmpty(pathBase)) |
|
|
|
{ |
|
|
|
app.UsePathBase(pathBase); |
|
|
|
} |
|
|
|
|
|
|
|
app.UseHealthChecksUI(config => |
|
|
|
{ |
|
|
|
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources"; |
|
|
|
config.UIPath = "/hc-ui"; |
|
|
|
}); |
|
|
|
app.UseHealthChecksUI(config => |
|
|
|
{ |
|
|
|
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources"; |
|
|
|
config.UIPath = "/hc-ui"; |
|
|
|
}); |
|
|
|
|
|
|
|
app.UseStaticFiles(); |
|
|
|
app.UseStaticFiles(); |
|
|
|
|
|
|
|
app.UseRouting(); |
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
app.UseRouting(); |
|
|
|
app.UseEndpoints(endpoints => |
|
|
|
{ |
|
|
|
endpoints.MapDefaultControllerRoute(); |
|
|
|
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions |
|
|
|
{ |
|
|
|
endpoints.MapDefaultControllerRoute(); |
|
|
|
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions |
|
|
|
{ |
|
|
|
Predicate = r => r.Name.Contains("self") |
|
|
|
}); |
|
|
|
Predicate = r => r.Name.Contains("self") |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private void RegisterAppInsights(IServiceCollection services) |
|
|
|
{ |
|
|
|
services.AddApplicationInsightsTelemetry(Configuration); |
|
|
|
services.AddApplicationInsightsKubernetesEnricher(); |
|
|
|
} |
|
|
|
private void RegisterAppInsights(IServiceCollection services) |
|
|
|
{ |
|
|
|
services.AddApplicationInsightsTelemetry(Configuration); |
|
|
|
services.AddApplicationInsightsKubernetesEnricher(); |
|
|
|
} |
|
|
|
} |