Skip to content

Commit

Permalink
Logging updates
Browse files Browse the repository at this point in the history
  • Loading branch information
leewrigh committed Feb 20, 2024
1 parent f8108cf commit e173a0d
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
25 changes: 24 additions & 1 deletion backend/DIAMConfiguration/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

var builder = WebApplication.CreateBuilder(args);

var name = Assembly.GetExecutingAssembly().GetName();
var outputTemplate = "[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}";
var path = Environment.GetEnvironmentVariable("LogFilePath") ?? "logs";





// Add services to the container.

var dbConnection = builder.Configuration.GetValue<string>("ConfigDatabase");
Expand All @@ -24,6 +32,12 @@
})
.EnableSensitiveDataLogging(sensitiveDataLoggingEnabled: false));

builder.Host.UseSerilog((hostContext, services, configuration) =>
{
configuration.ReadFrom.Configuration(hostContext.Configuration);
});


builder.Services.AddHealthChecks()
.AddCheck("liveness", () => HealthCheckResult.Healthy())
.AddNpgSql(dbConnection, tags: new[] { "services" }).ForwardToPrometheus();
Expand Down Expand Up @@ -61,7 +75,14 @@
app.MapHealthChecks("/health/liveness");
app.MapMetrics("/health/metrics");


app.UseSerilogRequestLogging(options => options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
{
//var userId = httpContext.User.GetUserId();
//if (!userId.Equals(Guid.Empty))
//{
// diagnosticContext.Set("User", userId);
//}
});

app.UseHttpsRedirection();

Expand All @@ -87,3 +108,5 @@
Log.Logger.Information("### Approval Flow Configuration complete");

app.Run();


36 changes: 35 additions & 1 deletion backend/DIAMConfiguration/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,39 @@
}
},
"AllowedHosts": "*",
"ConfigDatabase": "Host=fedora;Port=5444;Database=diam-config;Username=diamconfig;Password=P@55w0rd"
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
},
"Enrich": [
"FromLogContext"
],
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "RequestPath like '/health%'"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "../logs/dev/dev.log",
"rollingInterval": "Day",
"outputTemplate": "{Level:w5} [{Timestamp:yyyy-MM-dd HH:mm:ss,fff}] >> {Message}{NewLine}{Exception}"
}
},
{
"Name": "Console",
"Args": {
"outputTemplate": "{Level:w5} [{Timestamp:yyyy-MM-dd HyH:mm:ss,fff}] >> {Message}{NewLine}{Exception}"
}
}
]
}
}

0 comments on commit e173a0d

Please sign in to comment.