Skip to content

Commit 7603175

Browse files
authored
Merge pull request #56 from PandaTechAM/development
logging performance boost
2 parents 99ff363 + ccc09df commit 7603175

File tree

3 files changed

+24
-57
lines changed

3 files changed

+24
-57
lines changed

SharedKernel.Demo/appsettings.Development.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"MinimumLevel": {
44
"Default": "Information",
55
"Override": {
6-
"Microsoft": "Warning",
7-
"System": "Warning"
6+
"Microsoft": "Information",
7+
"System": "Information"
88
}
99
}
1010
},

src/SharedKernel/Logging/SerilogExtensions.cs

Lines changed: 20 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,11 @@ private static LoggerConfiguration WriteToFile(this LoggerConfiguration loggerCo
116116
if (useAsync)
117117
{
118118
return loggerConfig.WriteTo.Async(a =>
119-
a.File(formatter,
120-
logPath,
121-
rollingInterval: RollingInterval.Day)
122-
);
119+
a.File(formatter,
120+
logPath,
121+
rollingInterval: RollingInterval.Day),
122+
blockWhenFull: true,
123+
bufferSize: 20_000);
123124
}
124125

125126
return loggerConfig.WriteTo.File(formatter, logPath, rollingInterval: RollingInterval.Day);
@@ -129,59 +130,26 @@ private static LoggerConfiguration FilterOutUnwantedLogs(this LoggerConfiguratio
129130
{
130131
return loggerConfig
131132
.Filter
132-
.ByExcluding(e => e.ShouldExcludeAboveBoardGetLogs())
133+
.ByExcluding(e => e.ExcludeOutboxAndMassTransit())
133134
.Filter
134-
.ByExcluding(e => e.ShouldExcludeHangfireDashboardLogs())
135-
.Filter
136-
.ByExcluding(e => e.ShouldExcludeOutboxDbCommandLogs())
137-
.Filter
138-
.ByExcluding(e => e.ShouldExcludeSwaggerLogs())
139-
.Filter
140-
.ByExcluding(e => e.ShouldExcludeMassTransitHealthCheckLogs());
141-
}
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-
}
156-
157-
private static bool ShouldExcludeHangfireDashboardLogs(this LogEvent logEvent)
158-
{
159-
return logEvent.Properties.TryGetValue("RequestPath", out var requestPathValue)
160-
&& requestPathValue is ScalarValue requestPath
161-
&& requestPath.Value
162-
?.ToString()
163-
?.Contains("/hangfire") == true;
135+
.ByExcluding(evt =>
136+
{
137+
if (!evt.Properties.TryGetValue("RequestPath", out var p) || p is not ScalarValue sv)
138+
return false;
139+
var path = sv.Value as string ?? "";
140+
return path.StartsWith("/swagger")
141+
|| path.StartsWith("/hangfire")
142+
|| path.Contains("/above-board")
143+
|| path.Contains("localhost/auth/is-authenticated.json?api-version=v2");
144+
});
164145
}
165146

166-
private static bool ShouldExcludeOutboxDbCommandLogs(this LogEvent logEvent)
147+
private static bool ExcludeOutboxAndMassTransit(this LogEvent logEvent)
167148
{
168149
var message = logEvent.RenderMessage();
169-
return message.Contains("outbox_messages", StringComparison.OrdinalIgnoreCase);
170-
}
171-
172-
private static bool ShouldExcludeSwaggerLogs(this LogEvent logEvent)
173-
{
174-
return logEvent.Properties.TryGetValue("RequestPath", out var requestPathValue)
175-
&& requestPathValue is ScalarValue requestPath
176-
&& requestPath.Value
177-
?.ToString()
178-
?.Contains("/swagger") == true;
179-
}
180-
181-
private static bool ShouldExcludeMassTransitHealthCheckLogs(this LogEvent logEvent)
182-
{
183-
var message = logEvent.RenderMessage();
184-
return message.StartsWith("Health check masstransit-bus with status Unhealthy completed after");
150+
return message.Contains("outbox_messages", StringComparison.OrdinalIgnoreCase) || message.StartsWith(
151+
"Health check masstransit-bus with status Unhealthy completed after",
152+
StringComparison.OrdinalIgnoreCase);
185153
}
186154

187155
private static string GetLogsPath(this WebApplicationBuilder builder)
@@ -194,5 +162,4 @@ private static string GetLogsPath(this WebApplicationBuilder builder)
194162
var fileName = $"logs-{instanceId}-.json";
195163
return Path.Combine(persistencePath, repoName, envName, "logs", fileName);
196164
}
197-
198165
}

src/SharedKernel/SharedKernel.csproj

Lines changed: 2 additions & 2 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.1</Version>
11+
<Version>1.5.2</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>Logging cleanup and nuget updates</PackageReleaseNotes>
17+
<PackageReleaseNotes>Logging performance boost</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)