Skip to content

Commit

Permalink
Merged PR 8031: Add exclusionPatterns to ConfigureLogging
Browse files Browse the repository at this point in the history
Add exclusionPatterns to ConfigureLogging
  • Loading branch information
vip32 committed Sep 9, 2024
1 parent b0db542 commit df236f3
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 3 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<PackageVersion Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageVersion Include="Serilog.Enrichers.ShortTypeName" Version="1.1.0" />
<PackageVersion Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageVersion Include="Serilog.Expressions" Version="5.0.0" />
<PackageVersion Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageVersion Include="Serilog.Settings.Configuration" Version="8.0.2" />
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -3008,6 +3009,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2472,6 +2472,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -3323,6 +3324,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -3008,6 +3009,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -3252,6 +3253,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
10 changes: 10 additions & 0 deletions examples/DinnerFiesta/Presentation.Web.Server/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -2794,6 +2795,15 @@
"resolved": "4.0.1",
"contentHash": "pzeDRXdpSLSsgBHpZcmpIDxqMy845Ab4s+dfnBg0sN9h8q/4Wo3vAoe0QCGPze1Q06EVtEPupS+UvLm8iXQmTQ=="
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -2846,6 +2847,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2082,6 +2082,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -2915,6 +2916,15 @@
"Serilog": "4.0.0"
}
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2005,6 +2005,7 @@
"Ensure.That": "[10.1.0, )",
"Microsoft.Extensions.Configuration.Abstractions": "[8.0.0, )",
"Serilog": "[4.0.1, )",
"Serilog.Expressions": "[5.0.0, )",
"Serilog.Extensions.Hosting": "[8.0.0, )",
"Serilog.Settings.Configuration": "[8.0.2, )",
"Serilog.Sinks.Console": "[6.0.0, )",
Expand Down Expand Up @@ -2632,6 +2633,15 @@
"resolved": "4.0.1",
"contentHash": "pzeDRXdpSLSsgBHpZcmpIDxqMy845Ab4s+dfnBg0sN9h8q/4Wo3vAoe0QCGPze1Q06EVtEPupS+UvLm8iXQmTQ=="
},
"Serilog.Expressions": {
"type": "CentralTransitive",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "CentralTransitive",
"requested": "[8.0.0, )",
Expand Down
17 changes: 14 additions & 3 deletions src/Presentation.Serilog/HostBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace BridgingIT.DevKit.Presentation;
public static class HostBuilderExtensions
{
//[Obsolete("Use the new builder.Host.ConfigureLogging(), without the configuration argument")]
public static IHostBuilder ConfigureLogging(this IHostBuilder builder, IConfiguration configuration = null)
public static IHostBuilder ConfigureLogging(this IHostBuilder builder, IConfiguration configuration = null, string[] exclusionPatterns = null)
{
// return builder.ConfigureLogging();
//}
Expand All @@ -26,9 +26,20 @@ public static IHostBuilder ConfigureLogging(this IHostBuilder builder, IConfigur

if (Log.Logger.GetType().Name == "SilentLogger") // only setup serilog if not done already
{
builder.ConfigureLogging((Action<HostBuilderContext, ILoggingBuilder>)((ctx, c) =>
builder.ConfigureLogging((ctx, c) =>
{
var loggerConfiguration = new LoggerConfiguration();
loggerConfiguration.Filter.ByExcluding("RequestPath like '/health%'"); // exclude health checks from logs
loggerConfiguration.Filter.ByExcluding("RequestPath like '/api/events/raw'"); // exclude otel push from logs
loggerConfiguration.Filter.ByExcluding("StartsWith(@Message, 'Execution attempt. Source')"); // exclude health/otel from logs

if (exclusionPatterns != null)
{
foreach (var exclusionPattern in exclusionPatterns)
{
loggerConfiguration.Filter.ByExcluding(exclusionPattern);
}
}

if (configuration != null)
{
Expand All @@ -43,7 +54,7 @@ public static IHostBuilder ConfigureLogging(this IHostBuilder builder, IConfigur
builder.UseSerilog(logger);

Log.Logger = logger;
}));
});
}

return builder;
Expand Down
1 change: 1 addition & 0 deletions src/Presentation.Serilog/Presentation.Serilog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" />
<PackageReference Include="Serilog" />
<PackageReference Include="Serilog.Expressions" />
<PackageReference Include="Serilog.Extensions.Hosting" />
<PackageReference Include="Serilog.Settings.Configuration" />
<PackageReference Include="Serilog.Sinks.Console" />
Expand Down
9 changes: 9 additions & 0 deletions src/Presentation.Serilog/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
"resolved": "4.0.1",
"contentHash": "pzeDRXdpSLSsgBHpZcmpIDxqMy845Ab4s+dfnBg0sN9h8q/4Wo3vAoe0QCGPze1Q06EVtEPupS+UvLm8iXQmTQ=="
},
"Serilog.Expressions": {
"type": "Direct",
"requested": "[5.0.0, )",
"resolved": "5.0.0",
"contentHash": "QhZjXtUcA2QfQRA60m+DfyIfidKsQV7HBstbYEDqzJKMbJH/KnKthkkjciRuYrmFE+scWv1JibC5LlXrdtOUmw==",
"dependencies": {
"Serilog": "4.0.0"
}
},
"Serilog.Extensions.Hosting": {
"type": "Direct",
"requested": "[8.0.0, )",
Expand Down

0 comments on commit df236f3

Please sign in to comment.