-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f1fca13
commit 189caeb
Showing
1 changed file
with
67 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,78 @@ | ||
using Azure.Identity; | ||
using Microsoft.ApplicationInsights.Extensibility; | ||
using Serilog; | ||
using Serilog.Events; | ||
using Serilog.Sinks.SystemConsole.Themes; | ||
using WorkshopDemo.Core.Common; | ||
using WorkshopDemo.HealthChecks; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Add services to the container. | ||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddOpenApi(); | ||
builder.Services.AddControllers(); | ||
builder.Services.AddHealthChecks() | ||
.AddCheck<WorkshopDemoHealthCheck>(nameof(WorkshopDemoHealthCheck)); | ||
builder.Services.AddSingleton<IFileService, FileService>(); | ||
builder.Services.AddSingleton<IVersionService, VersionService>(); | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.Enrich.FromLogContext() | ||
.WriteTo.Console() | ||
.CreateBootstrapLogger(); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
try | ||
{ | ||
app.MapOpenApi(); | ||
} | ||
Log.Information("Starting web host"); | ||
|
||
// Add services to the container. | ||
builder.Host.UseSerilog((ctx, lc) => lc | ||
.MinimumLevel.Information() | ||
.MinimumLevel.Override("WorkshopDemo", LogEventLevel.Debug) | ||
.MinimumLevel.Override("System", LogEventLevel.Error) | ||
.WriteTo.Console( | ||
outputTemplate: | ||
"[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", | ||
theme: AnsiConsoleTheme.Literate) | ||
.WriteTo.ApplicationInsights( | ||
new TelemetryConfiguration | ||
{ ConnectionString = ctx.Configuration.GetConnectionString("ApplicationInsights") }, | ||
TelemetryConverter.Traces) | ||
.Enrich.FromLogContext()); | ||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddOpenApi(); | ||
builder.Services.AddControllers(); | ||
builder.Services.AddHealthChecks() | ||
.AddCheck<WorkshopDemoHealthCheck>(nameof(WorkshopDemoHealthCheck)); | ||
builder.Services.AddSingleton<IFileService, FileService>(); | ||
builder.Services.AddSingleton<IVersionService, VersionService>(); | ||
|
||
builder.Configuration.AddAzureKeyVault( | ||
new Uri($"https://kv-scottsauber-{builder.Environment.EnvironmentName}.vault.azure.net/"), | ||
new ChainedTokenCredential(new AzureCliCredential(), new ManagedIdentityCredential())); | ||
|
||
builder.Services.AddApplicationInsightsTelemetry(options => | ||
{ | ||
options.ConnectionString = builder.Configuration.GetConnectionString("ApplicationInsights"); | ||
}); | ||
|
||
var app = builder.Build(); | ||
|
||
app.UseSerilogRequestLogging(); | ||
|
||
app.UseHttpsRedirection(); | ||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.MapOpenApi(); | ||
} | ||
|
||
app.MapHealthChecks("/api/healthz"); | ||
app.UseHttpsRedirection(); | ||
|
||
app.MapControllers(); | ||
app.MapHealthChecks("/api/healthz"); | ||
|
||
app.Run(); | ||
app.MapControllers(); | ||
|
||
app.Run(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Log.Fatal(ex, "Application terminated"); | ||
} | ||
finally | ||
{ | ||
Log.CloseAndFlush(); | ||
} |