diff --git a/src/BuildingBlocks/Logging/LogEnrichHelper.cs b/src/BuildingBlocks/Logging/LogEnrichHelper.cs new file mode 100644 index 0000000..ecf5c6c --- /dev/null +++ b/src/BuildingBlocks/Logging/LogEnrichHelper.cs @@ -0,0 +1,39 @@ +using System.Security.Claims; +using Microsoft.AspNetCore.Http; +using Serilog; + +namespace BuildingBlocks.Logging; + +public static class LogEnrichHelper +{ + //ref: https://andrewlock.net/using-serilog-aspnetcore-in-asp-net-core-3-logging-the-selected-endpoint-name-with-serilog/ + public static void EnrichFromRequest(IDiagnosticContext diagnosticContext, HttpContext httpContext) + { + var request = httpContext.Request; + + // Set all the common properties available for every request + diagnosticContext.Set("Host", request.Host); + diagnosticContext.Set("Protocol", request.Protocol); + diagnosticContext.Set("Scheme", request.Scheme); + + // Only set it if available. You're not sending sensitive data in a querystring right?! + if(request.QueryString.HasValue) + { + diagnosticContext.Set("QueryString", request.QueryString.Value); + } + + // Set the content-type of the Response at this point + diagnosticContext.Set("ContentType", httpContext.Response.ContentType); + + // Retrieve the IEndpointFeature selected for the request + var endpoint = httpContext.GetEndpoint(); + if (endpoint is object) // endpoint != null + { + diagnosticContext.Set("EndpointName", endpoint.DisplayName); + } + + diagnosticContext.Set("ClientIP", httpContext.Connection.RemoteIpAddress); + + diagnosticContext.Set("UserId", request.HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier)); + } +} diff --git a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs index c0d7dde..4631559 100644 --- a/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Booking/src/Booking/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -94,7 +94,10 @@ public static class InfrastructureExtensions var appOptions = app.GetOptions(nameof(AppOptions)); app.UseProblemDetails(); - app.UseSerilogRequestLogging(); + app.UseSerilogRequestLogging(options => + { + options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; + }); app.UseCorrelationId(); app.UseRouting(); app.UseHttpMetrics(); diff --git a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs index dd53410..729a253 100644 --- a/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Flight/src/Flight/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -101,7 +101,10 @@ public static class InfrastructureExtensions var appOptions = app.GetOptions(nameof(AppOptions)); app.UseProblemDetails(); - app.UseSerilogRequestLogging(); + app.UseSerilogRequestLogging(options => + { + options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; + }); app.UseCorrelationId(); app.UseHttpMetrics(); app.UseMigration(env); diff --git a/src/Services/Identity/src/Identity.Api/keys/is-signing-key-B33EF2DCF9AAEDDA74F42B239C122EC3.json b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-B33EF2DCF9AAEDDA74F42B239C122EC3.json new file mode 100644 index 0000000..73a5ff9 --- /dev/null +++ b/src/Services/Identity/src/Identity.Api/keys/is-signing-key-B33EF2DCF9AAEDDA74F42B239C122EC3.json @@ -0,0 +1 @@ +{"Version":1,"Id":"B33EF2DCF9AAEDDA74F42B239C122EC3","Created":"2022-12-21T12:54:30.8778452Z","Algorithm":"RS256","IsX509Certificate":false,"Data":"CfDJ8BYS1jC_Z-ZPsg3E7DQNOTPJbX5na2yKwYTMzyoQuiVxDh2roPqW5hjhMHjO5KyMi0Hg_JgQ6TmQ8hgf-4kff-Z3PtIlT2ydkdtv0ZIljsrCbma4CFulhcRah8UczQetDDhe8CITbqTPnmX0Erz_MuBTt8f2zlj1Ne_OsuqyKYUCu_yo8SEy5vYT-_Q1626X77NtbvyWg8NheVKZadglyxml9X6AFe6zh3kRBX7odVWW0d45N9aQodGDq-Bv2h4DiLC_h5mtmwWcUTvwCQ5G4ix_12BSl_NzyDpkqZH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jHLeKr2DvjwLEVph2yR1UD7D","DataProtected":true} \ No newline at end of file diff --git a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs index 4737933..9303215 100644 --- a/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Identity/src/Identity/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -85,7 +85,10 @@ public static class InfrastructureExtensions var appOptions = app.GetOptions(nameof(AppOptions)); app.UseProblemDetails(); - app.UseSerilogRequestLogging(); + app.UseSerilogRequestLogging(options => + { + options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; + }); app.UseMigration(env); app.UseCorrelationId(); app.UseHttpMetrics(); diff --git a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs index f902d7a..28f38e9 100644 --- a/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs +++ b/src/Services/Passenger/src/Passenger/Extensions/Infrastructure/InfrastructureExtensions.cs @@ -92,7 +92,10 @@ public static class InfrastructureExtensions var appOptions = app.GetOptions(nameof(AppOptions)); app.UseProblemDetails(); - app.UseSerilogRequestLogging(); + app.UseSerilogRequestLogging(options => + { + options.EnrichDiagnosticContext = LogEnrichHelper.EnrichFromRequest; + }); app.UseMigration(env); app.UseCorrelationId(); app.UseHttpMetrics();