Skip to content

Commit 859eecf

Browse files
committed
Logging cleanup and nuget updates
1 parent 7d11445 commit 859eecf

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

SharedKernel.Demo/SharedKernel.Demo.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

src/SharedKernel/Helpers/MethodTimingStatistics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private static string FormatDuration(double milliseconds)
107107
if (seconds < 60)
108108
{
109109
var wholeSeconds = (int)seconds;
110-
var remainderMs = milliseconds - (wholeSeconds * 1000.0);
110+
var remainderMs = milliseconds - wholeSeconds * 1000.0;
111111
return $"{wholeSeconds}s {remainderMs:F3}ms";
112112
}
113113

src/SharedKernel/Logging/OutboundLoggingHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
2929
response.Content.Headers.ContentType?.MediaType);
3030

3131
logger.LogInformation(
32-
"[Outbound Call] HTTP {Method} to {Uri} responded with {StatusCode} in {ElapsedMs}ms. " +
32+
"[Outbound Call] HTTP {Method} {Uri} responded with {StatusCode} in {ElapsedMs}ms. " +
3333
"Request Headers: {RequestHeaders}, Request Body: {RequestBody}, " +
3434
"Response Headers: {ResponseHeaders}, Response Body: {ResponseBody}",
3535
request.Method,
36-
request.RequestUri,
36+
request.RequestUri?.ToString(),
3737
(int)response.StatusCode,
3838
elapsed,
3939
reqHeaders,

src/SharedKernel/Logging/RequestLoggingMiddleware.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Http.Extensions;
34
using Microsoft.Extensions.Logging;
45
using SharedKernel.Logging.Helpers;
56

@@ -52,11 +53,11 @@ public async Task InvokeAsync(HttpContext context)
5253
await responseBody.CopyToAsync(originalBody);
5354

5455
logger.LogInformation(
55-
"[Incoming Request] HTTP {Method} {Query} responded with {StatusCode} in {ElapsedMilliseconds}ms. " +
56+
"[Incoming Request] HTTP {Method} {Url} responded with {StatusCode} in {ElapsedMilliseconds}ms. " +
5657
"Request Headers: {RequestHeaders}, Request Body: {RequestBody}, " +
5758
"Response Headers: {ResponseHeaders}, Response Body: {ResponseBody}",
5859
context.Request.Method,
59-
context.Request.QueryString,
60+
context.Request.GetDisplayUrl(),
6061
context.Response.StatusCode,
6162
elapsed,
6263
reqHeaders,

src/SharedKernel/Logging/SerilogExtensions.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ private static LoggerConfiguration WriteToFile(this LoggerConfiguration loggerCo
125125
return loggerConfig.WriteTo.File(formatter, logPath, rollingInterval: RollingInterval.Day);
126126
}
127127

128-
#region Filtering
129-
130128
private static LoggerConfiguration FilterOutUnwantedLogs(this LoggerConfiguration loggerConfig)
131129
{
132130
return loggerConfig
131+
.Filter
132+
.ByExcluding(e => e.ShouldExcludeAboveBoardGetLogs())
133133
.Filter
134134
.ByExcluding(e => e.ShouldExcludeHangfireDashboardLogs())
135135
.Filter
@@ -139,6 +139,20 @@ private static LoggerConfiguration FilterOutUnwantedLogs(this LoggerConfiguratio
139139
.Filter
140140
.ByExcluding(e => e.ShouldExcludeMassTransitHealthCheckLogs());
141141
}
142+
143+
private static bool ShouldExcludeAboveBoardGetLogs(this LogEvent logEvent)
144+
{
145+
var path = logEvent.Properties.TryGetValue("RequestPath", out var p) && p is ScalarValue sv
146+
? sv.Value?.ToString()
147+
: null;
148+
149+
var method = logEvent.Properties.TryGetValue("RequestMethod", out var m) && m is ScalarValue mv
150+
? mv.Value?.ToString()
151+
: null;
152+
153+
return string.Equals(method, "GET", StringComparison.OrdinalIgnoreCase)
154+
&& path?.StartsWith("/above-board", StringComparison.OrdinalIgnoreCase) == true;
155+
}
142156

143157
private static bool ShouldExcludeHangfireDashboardLogs(this LogEvent logEvent)
144158
{
@@ -170,10 +184,6 @@ private static bool ShouldExcludeMassTransitHealthCheckLogs(this LogEvent logEve
170184
return message.StartsWith("Health check masstransit-bus with status Unhealthy completed after");
171185
}
172186

173-
#endregion
174-
175-
#region File Path Helper
176-
177187
private static string GetLogsPath(this WebApplicationBuilder builder)
178188
{
179189
var persistencePath = builder.Configuration.GetPersistentPath();
@@ -185,5 +195,4 @@ private static string GetLogsPath(this WebApplicationBuilder builder)
185195
return Path.Combine(persistencePath, repoName, envName, "logs", fileName);
186196
}
187197

188-
#endregion
189198
}

src/SharedKernel/SharedKernel.csproj

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.5.0</Version>
11+
<Version>1.5.1</Version>
1212
<PackageId>Pandatech.SharedKernel</PackageId>
1313
<Title>Pandatech Shared Kernel Library</Title>
1414
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
1515
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
17-
<PackageReleaseNotes>FluentValidation nuget change from ASPNETCORE to regular one. This might brake some code</PackageReleaseNotes>
17+
<PackageReleaseNotes>Logging cleanup and nuget updates</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>
@@ -29,17 +29,17 @@
2929
<ItemGroup>
3030
<PackageReference Include="AspNetCore.HealthChecks.Prometheus.Metrics" Version="9.0.0" />
3131
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="9.0.0" />
32-
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.18.1" />
32+
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.18.2" />
3333
<PackageReference Include="FluentDateTime" Version="3.0.0" />
3434
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="12.0.0" />
35-
<PackageReference Include="HtmlSanitizer" Version="9.0.884" />
36-
<PackageReference Include="MediatR" Version="12.5.0" />
37-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" />
38-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.5" />
39-
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="9.0.5" />
40-
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.5" />
41-
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.5" />
42-
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.5.0" />
35+
<PackageReference Include="HtmlSanitizer" Version="9.0.886" />
36+
<PackageReference Include="MediatR" Version="[12.5.0]" />
37+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.7" />
38+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.7" />
39+
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="9.0.7" />
40+
<PackageReference Include="Microsoft.AspNetCore.SignalR.StackExchangeRedis" Version="9.0.7" />
41+
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.7" />
42+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.7.0" />
4343
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.12.0" />
4444
<PackageReference Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.8.0-rc.1" />
4545
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
@@ -53,11 +53,11 @@
5353
<PackageReference Include="Pandatech.FluentMinimalApiMapper" Version="2.0.3" />
5454
<PackageReference Include="Pandatech.PandaVaultClient" Version="4.0.5" />
5555
<PackageReference Include="Pandatech.ResponseCrafter" Version="5.1.10" />
56-
<PackageReference Include="Scalar.AspNetCore" Version="2.4.13" />
56+
<PackageReference Include="Scalar.AspNetCore" Version="2.5.6" />
5757
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
5858
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
5959
<PackageReference Include="Serilog.Sinks.Grafana.Loki" Version="8.3.1" />
60-
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.1.4" />
60+
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="9.0.3" />
6161
</ItemGroup>
6262

6363
</Project>

0 commit comments

Comments
 (0)