Included scoped namespace
This commit is contained in:
parent
d4d70ab821
commit
3e769f9972
@ -1,41 +1,36 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
namespace WebStatus.Controllers;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
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)
|
public IActionResult Index()
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
var basePath = _configuration["PATH_BASE"];
|
||||||
}
|
return Redirect($"{basePath}/hc-ui");
|
||||||
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
[HttpGet("/Config")]
|
||||||
{
|
public IActionResult Config()
|
||||||
var basePath = _configuration["PATH_BASE"];
|
{
|
||||||
return Redirect($"{basePath}/hc-ui");
|
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")]
|
return View(configurationValues);
|
||||||
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);
|
public IActionResult Error()
|
||||||
}
|
{
|
||||||
|
return View();
|
||||||
public IActionResult Error()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,4 @@
|
|||||||
using Microsoft.AspNetCore;
|
var configuration = GetConfiguration();
|
||||||
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();
|
|
||||||
|
|
||||||
Log.Logger = CreateSerilogLogger(configuration);
|
Log.Logger = CreateSerilogLogger(configuration);
|
||||||
|
|
||||||
@ -116,7 +103,7 @@ void LogPackagesVersionInfo()
|
|||||||
Log.Logger.ForContext("PackageVersions", string.Join("\n", versionList)).Information("Package versions ({ApplicationContext})", Program.AppName);
|
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;
|
private static readonly string _namespace = typeof(Startup).Namespace;
|
||||||
public static readonly string AppName = _namespace;
|
public static readonly string AppName = _namespace;
|
||||||
|
@ -1,87 +1,76 @@
|
|||||||
using Microsoft.AspNetCore.Builder;
|
namespace WebStatus;
|
||||||
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
|
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; }
|
var pathBase = Configuration["PATH_BASE"];
|
||||||
|
if (!string.IsNullOrEmpty(pathBase))
|
||||||
// This method gets called by the runtime. Use this method to add services to the container.
|
|
||||||
public void ConfigureServices(IServiceCollection services)
|
|
||||||
{
|
{
|
||||||
RegisterAppInsights(services);
|
app.UsePathBase(pathBase);
|
||||||
|
|
||||||
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.
|
app.UseHealthChecksUI(config =>
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
|
|
||||||
{
|
{
|
||||||
//loggerFactory.AddAzureWebAppDiagnostics();
|
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
||||||
//loggerFactory.AddApplicationInsights(app.ApplicationServices, LogLevel.Trace);
|
config.UIPath = "/hc-ui";
|
||||||
|
});
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
app.UseStaticFiles();
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
app.UseExceptionHandler("/Home/Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
var pathBase = Configuration["PATH_BASE"];
|
app.UseRouting();
|
||||||
if (!string.IsNullOrEmpty(pathBase))
|
app.UseEndpoints(endpoints =>
|
||||||
|
{
|
||||||
|
endpoints.MapDefaultControllerRoute();
|
||||||
|
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||||
{
|
{
|
||||||
app.UsePathBase(pathBase);
|
Predicate = r => r.Name.Contains("self")
|
||||||
}
|
|
||||||
|
|
||||||
app.UseHealthChecksUI(config =>
|
|
||||||
{
|
|
||||||
config.ResourcesPath = string.IsNullOrEmpty(pathBase) ? "/ui/resources" : $"{pathBase}/ui/resources";
|
|
||||||
config.UIPath = "/hc-ui";
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
app.UseStaticFiles();
|
private void RegisterAppInsights(IServiceCollection services)
|
||||||
|
{
|
||||||
app.UseRouting();
|
services.AddApplicationInsightsTelemetry(Configuration);
|
||||||
app.UseEndpoints(endpoints =>
|
services.AddApplicationInsightsKubernetesEnricher();
|
||||||
{
|
|
||||||
endpoints.MapDefaultControllerRoute();
|
|
||||||
endpoints.MapHealthChecks("/liveness", new HealthCheckOptions
|
|
||||||
{
|
|
||||||
Predicate = r => r.Name.Contains("self")
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RegisterAppInsights(IServiceCollection services)
|
|
||||||
{
|
|
||||||
services.AddApplicationInsightsTelemetry(Configuration);
|
|
||||||
services.AddApplicationInsightsKubernetesEnricher();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user