From e3c052d85f3c9c7d14801a4f3d80bc1be0436483 Mon Sep 17 00:00:00 2001 From: Marek Matulka Date: Wed, 2 Oct 2024 15:14:31 +0100 Subject: [PATCH] DP-671: Include version in logs --- Frontend/CO.CDP.OrganisationApp/Program.cs | 2 +- .../CO.CDP.AwsServices/CloudWatchExtensions.cs | 18 ++++++++++-------- Services/CO.CDP.DataSharing.WebApi/Program.cs | 2 +- Services/CO.CDP.EntityVerification/Program.cs | 2 +- Services/CO.CDP.Forms.WebApi/Program.cs | 2 +- .../CO.CDP.Organisation.Authority/Program.cs | 2 +- Services/CO.CDP.Organisation.WebApi/Program.cs | 2 +- Services/CO.CDP.Person.WebApi/Program.cs | 2 +- Services/CO.CDP.Tenant.WebApi/Program.cs | 2 +- 9 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp/Program.cs b/Frontend/CO.CDP.OrganisationApp/Program.cs index 5b0bdba35..1f0f3d3f7 100644 --- a/Frontend/CO.CDP.OrganisationApp/Program.cs +++ b/Frontend/CO.CDP.OrganisationApp/Program.cs @@ -164,7 +164,7 @@ .AddAwsS3Service() .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); var app = builder.Build(); diff --git a/Libraries/CO.CDP.AwsServices/CloudWatchExtensions.cs b/Libraries/CO.CDP.AwsServices/CloudWatchExtensions.cs index 6cda42a0d..5cc2729a0 100644 --- a/Libraries/CO.CDP.AwsServices/CloudWatchExtensions.cs +++ b/Libraries/CO.CDP.AwsServices/CloudWatchExtensions.cs @@ -63,23 +63,25 @@ private static IServiceCollection AddCloudWatchLogs(this IServiceCollection serv }); } - public static IServiceCollection AddCloudWatchSerilog(this IServiceCollection services) + public static IServiceCollection AddCloudWatchSerilog( + this IServiceCollection services, IConfiguration configuration) { - return AddCloudWatchSerilog(services, (_, _) => { }); + return AddCloudWatchSerilog(services, configuration, (_, _) => { }); } private static IServiceCollection AddCloudWatchSerilog( - this IServiceCollection services, + this IServiceCollection services, IConfiguration configuration, Action configureLogger) { return services.AddSerilog((serviceProvider, lc) => { - var configuration = serviceProvider.GetRequiredService>().Value; + var loggingConfiguration = serviceProvider.GetRequiredService>().Value; lc.WriteTo.AmazonCloudWatch(serviceProvider) - .MinimumLevel.Is(configuration.MinimumLevel.Default) - .OverrideLogLevels(configuration.MinimumLevel.Override) - .EnableConsole(configuration.Console) - .Enrich.FromLogContext(); + .MinimumLevel.Is(loggingConfiguration.MinimumLevel.Default) + .OverrideLogLevels(loggingConfiguration.MinimumLevel.Override) + .EnableConsole(loggingConfiguration.Console) + .Enrich.FromLogContext() + .Enrich.WithProperty("Version", configuration.GetValue("Version")); configureLogger(serviceProvider, lc); }); } diff --git a/Services/CO.CDP.DataSharing.WebApi/Program.cs b/Services/CO.CDP.DataSharing.WebApi/Program.cs index 04c1857c9..0574d230e 100644 --- a/Services/CO.CDP.DataSharing.WebApi/Program.cs +++ b/Services/CO.CDP.DataSharing.WebApi/Program.cs @@ -55,7 +55,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } var app = builder.Build(); diff --git a/Services/CO.CDP.EntityVerification/Program.cs b/Services/CO.CDP.EntityVerification/Program.cs index 6403c8646..13e22d6dc 100644 --- a/Services/CO.CDP.EntityVerification/Program.cs +++ b/Services/CO.CDP.EntityVerification/Program.cs @@ -58,7 +58,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } builder.Services diff --git a/Services/CO.CDP.Forms.WebApi/Program.cs b/Services/CO.CDP.Forms.WebApi/Program.cs index 6b825fccf..f00bce639 100644 --- a/Services/CO.CDP.Forms.WebApi/Program.cs +++ b/Services/CO.CDP.Forms.WebApi/Program.cs @@ -48,7 +48,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } var app = builder.Build(); diff --git a/Services/CO.CDP.Organisation.Authority/Program.cs b/Services/CO.CDP.Organisation.Authority/Program.cs index af4f45d8d..9d8f2f2dd 100644 --- a/Services/CO.CDP.Organisation.Authority/Program.cs +++ b/Services/CO.CDP.Organisation.Authority/Program.cs @@ -32,7 +32,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } var app = builder.Build(); diff --git a/Services/CO.CDP.Organisation.WebApi/Program.cs b/Services/CO.CDP.Organisation.WebApi/Program.cs index b98a4b706..ce7d2ec2d 100644 --- a/Services/CO.CDP.Organisation.WebApi/Program.cs +++ b/Services/CO.CDP.Organisation.WebApi/Program.cs @@ -99,7 +99,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } var app = builder.Build(); diff --git a/Services/CO.CDP.Person.WebApi/Program.cs b/Services/CO.CDP.Person.WebApi/Program.cs index c8b38d3b3..a693fc29e 100644 --- a/Services/CO.CDP.Person.WebApi/Program.cs +++ b/Services/CO.CDP.Person.WebApi/Program.cs @@ -43,7 +43,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); } var app = builder.Build(); diff --git a/Services/CO.CDP.Tenant.WebApi/Program.cs b/Services/CO.CDP.Tenant.WebApi/Program.cs index 3c6f70c92..d15712072 100644 --- a/Services/CO.CDP.Tenant.WebApi/Program.cs +++ b/Services/CO.CDP.Tenant.WebApi/Program.cs @@ -46,7 +46,7 @@ .AddAwsConfiguration(builder.Configuration) .AddLoggingConfiguration(builder.Configuration) .AddAmazonCloudWatchLogsService() - .AddCloudWatchSerilog(); + .AddCloudWatchSerilog(builder.Configuration); builder.Services.AddHealthChecks() .AddNpgSql(ConnectionStringHelper.GetConnectionString(builder.Configuration,