Included scoped namespace
This commit is contained in:
parent
d4d70ab821
commit
3e769f9972
@ -1,41 +1,36 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System.Linq;
|
||||
namespace WebStatus.Controllers;
|
||||
|
||||
namespace WebStatus.Controllers
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public class HomeController : Controller
|
||||
private IConfiguration _configuration;
|
||||
|
||||
public HomeController(IConfiguration configuration)
|
||||
{
|
||||
private IConfiguration _configuration;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
public HomeController(IConfiguration configuration)
|
||||
{
|
||||
_configuration = configuration;
|
||||
}
|
||||
public IActionResult Index()
|
||||
{
|
||||
var basePath = _configuration["PATH_BASE"];
|
||||
return Redirect($"{basePath}/hc-ui");
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
var basePath = _configuration["PATH_BASE"];
|
||||
return Redirect($"{basePath}/hc-ui");
|
||||
}
|
||||
[HttpGet("/Config")]
|
||||
public IActionResult Config()
|
||||
{
|
||||
var configurationValues = _configuration.GetSection("HealthChecksUI:HealthChecks")
|
||||
.GetChildren()
|
||||
.SelectMany(cs => cs.GetChildren())
|
||||
.Union(_configuration.GetSection("HealthChecks-UI:HealthChecks")
|
||||
.GetChildren()
|
||||
.SelectMany(cs => cs.GetChildren()))
|
||||
.ToDictionary(v => v.Path, v => v.Value);
|
||||
|
||||
[HttpGet("/Config")]
|
||||
public IActionResult Config()
|
||||
{
|
||||
var configurationValues = _configuration.GetSection("HealthChecksUI:HealthChecks")
|
||||
.GetChildren()
|
||||
.SelectMany(cs => cs.GetChildren())
|
||||
.Union(_configuration.GetSection("HealthChecks-UI:HealthChecks")
|
||||
.GetChildren()
|
||||
.SelectMany(cs => cs.GetChildren()))
|
||||
.ToDictionary(v => v.Path, v => v.Value);
|
||||
return View(configurationValues);
|
||||
}
|
||||
|
||||
return View(configurationValues);
|
||||
}
|
||||
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
@ -1,17 +1,4 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using WebStatus;
|
||||
using Azure.Identity;
|
||||
using Azure.Core;
|
||||
|
||||
var configuration = GetConfiguration();
|
||||
var configuration = GetConfiguration();
|
||||
|
||||
Log.Logger = CreateSerilogLogger(configuration);
|
||||
|
||||
@ -116,7 +103,7 @@ void LogPackagesVersionInfo()
|
||||
Log.Logger.ForContext("PackageVersions", string.Join("\n", versionList)).Information("Package versions ({ApplicationContext})", Program.AppName);
|
||||
}
|
||||
|
||||
public class Program
|
||||
public partial class Program
|
||||
{
|
||||
private static readonly string _namespace = typeof(Startup).Namespace;
|
||||
public static readonly string AppName = _namespace;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
services.AddOptions();
|
||||
services.AddHealthChecks()
|
||||
.AddCheck("self", () => HealthCheckResult.Healthy());
|
||||
|
||||
services
|
||||
.AddHealthChecksUI()
|
||||
.AddInMemoryStorage();
|
||||
|
||||
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);
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
Configuration = configuration;
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
|
||||
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)
|
||||
var pathBase = Configuration["PATH_BASE"];
|
||||
if (!string.IsNullOrEmpty(pathBase))
|
||||
{
|
||||
RegisterAppInsights(services);
|
||||
|
||||
services.AddControllers();
|
||||
|
||||
services.AddOptions();
|
||||
services.AddHealthChecks()
|
||||
.AddCheck("self", () => HealthCheckResult.Healthy());
|
||||
|
||||
services
|
||||
.AddHealthChecksUI()
|
||||
.AddInMemoryStorage();
|
||||
|
||||
services.AddMvc()
|
||||
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
|
||||
app.UsePathBase(pathBase);
|
||||
}
|
||||
|
||||
// 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)
|
||||
app.UseHealthChecksUI(config =>
|
||||
{
|
||||
//loggerFactory.AddAzureWebAppDiagnostics();
|
||||
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
||||
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
||||
config.UIPath = "/hc-ui";
|
||||
});
|
||||
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Home/Error");
|
||||
}
|
||||
app.UseStaticFiles();
|
||||
|
||||
var pathBase = Configuration["PATH_BASE"];
|
||||
if (!string.IsNullOrEmpty(pathBase))
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
{
|
||||
app.UsePathBase(pathBase);
|
||||
}
|
||||
|
||||
app.UseHealthChecksUI(config =>
|
||||
{
|
||||
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
||||
config.UIPath = "/hc-ui";
|
||||
Predicate = r => r.Name.Contains("self")
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapDefaultControllerRoute();
|
||||
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user