Skip to content

Commit

Permalink
updated nugets and serilog
Browse files Browse the repository at this point in the history
  • Loading branch information
HaikAsatryan committed May 26, 2024
1 parent e0cfc08 commit 80162ac
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static WebApplicationBuilder AddSerilog(this WebApplicationBuilder builde
.Enrich.FromLogContext()
.Enrich.WithMachineName()
.Filter.ByExcluding(logEvent => logEvent.ShouldExcludeHangfireDashboardLogs())
.Filter.ByExcluding(logEvent => logEvent.ShouldExcludeOutboxDbCommandLogs(builder.Environment))
.ReadFrom.Configuration(configuration);

ConfigureEnvironmentSpecificSettings(builder.Environment, loggerConfig, elasticSearchUrl, indexName);
Expand Down Expand Up @@ -78,4 +79,15 @@ private static bool ShouldExcludeHangfireDashboardLogs(this LogEvent logEvent)
&& requestPathValue is ScalarValue requestPath
&& requestPath.Value?.ToString()?.Contains("/hangfire") == true;
}

private static bool ShouldExcludeOutboxDbCommandLogs(this LogEvent logEvent, IHostEnvironment environment)
{
if (!environment.IsLocalOrDevelopmentOrQa())
{
return false;
}
return logEvent.RenderMessage().StartsWith("Executed DbCommand") &&
(logEvent.RenderMessage().Contains("FROM outbox_messages") ||
logEvent.RenderMessage().Contains("FROM OutboxMessages"));
}
}

0 comments on commit 80162ac

Please sign in to comment.