formatting program.cs
This commit is contained in:
parent
52fb849b84
commit
24858e50b7
@ -1,8 +1,10 @@
|
|||||||
var appName = "Ordering.API";
|
var appName = "Ordering.API";
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
builder.WebHost.ConfigureAppConfiguration(cb => {
|
builder.WebHost.ConfigureAppConfiguration(cb =>
|
||||||
|
{
|
||||||
var sources = cb.Sources;
|
var sources = cb.Sources;
|
||||||
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource() {
|
sources.Insert(3, new Microsoft.Extensions.Configuration.Json.JsonConfigurationSource()
|
||||||
|
{
|
||||||
Optional = true,
|
Optional = true,
|
||||||
Path = "appsettings.localhost.json",
|
Path = "appsettings.localhost.json",
|
||||||
ReloadOnChange = false
|
ReloadOnChange = false
|
||||||
@ -22,14 +24,17 @@ builder.Services.AddCustomMvc(builder.Configuration)
|
|||||||
.AddApplicationServices()
|
.AddApplicationServices()
|
||||||
.AddGrpcServices();
|
.AddGrpcServices();
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
if (app.Environment.IsDevelopment()) {
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
}
|
}
|
||||||
var pathBase = builder.Configuration["PATH_BASE"];
|
var pathBase = builder.Configuration["PATH_BASE"];
|
||||||
if (!string.IsNullOrEmpty(pathBase)) {
|
if (!string.IsNullOrEmpty(pathBase))
|
||||||
|
{
|
||||||
app.UsePathBase(pathBase);
|
app.UsePathBase(pathBase);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,31 +57,35 @@ app.UseAuthorization();
|
|||||||
|
|
||||||
app.MapDefaultControllerRoute();
|
app.MapDefaultControllerRoute();
|
||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.MapHealthChecks("/hc", new HealthCheckOptions() {
|
app.MapHealthChecks("/hc", new HealthCheckOptions()
|
||||||
|
{
|
||||||
Predicate = _ => true,
|
Predicate = _ => true,
|
||||||
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
|
||||||
});
|
});
|
||||||
app.MapHealthChecks("/liveness", new HealthCheckOptions {
|
app.MapHealthChecks("/liveness", new HealthCheckOptions
|
||||||
|
{
|
||||||
Predicate = r => r.Name.Contains("self")
|
Predicate = r => r.Name.Contains("self")
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
Log.Information("Starts Web Application ({ApplicationContext})...", Program.AppName);
|
Log.Information("Starts Web Application ({ApplicationContext})...", Program.AppName);
|
||||||
await app.RunAsync();
|
await app.RunAsync();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex)
|
||||||
|
{
|
||||||
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
Log.Fatal(ex, "Program terminated unexpectedly ({ApplicationContext})!", Program.AppName);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
finally {
|
finally
|
||||||
|
{
|
||||||
Log.CloseAndFlush();
|
Log.CloseAndFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration)
|
||||||
Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) {
|
{
|
||||||
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
var seqServerUrl = configuration["Serilog:SeqServerUrl"];
|
||||||
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
var logstashUrl = configuration["Serilog:LogstashgUrl"];
|
||||||
return new LoggerConfiguration()
|
return new LoggerConfiguration()
|
||||||
@ -89,7 +98,8 @@ Serilog.ILogger CreateSerilogLogger(IConfiguration configuration) {
|
|||||||
.ReadFrom.Configuration(configuration)
|
.ReadFrom.Configuration(configuration)
|
||||||
.CreateLogger();
|
.CreateLogger();
|
||||||
}
|
}
|
||||||
public partial class Program {
|
public partial class Program
|
||||||
|
{
|
||||||
|
|
||||||
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
public static string Namespace = typeof(Program).Assembly.GetName().Name;
|
||||||
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
public static string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user