Skip to content

Commit 73a5eb1

Browse files
committed
fix globing
1 parent 9a34ae4 commit 73a5eb1

File tree

17 files changed

+791
-1039
lines changed

17 files changed

+791
-1039
lines changed

samples/EntityFramework/src/Tracker.Web/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ private static void ConfigureMiddleware(WebApplication app)
139139
app.UseResponseCompression();
140140
}
141141

142-
app.UseRequestLogging(config => config.IncludeRequestBody = true);
142+
app.UseRequestLogging(config =>
143+
{
144+
config.IncludeRequestBody = true;
145+
config.IgnorePath("/_framework/**");
146+
config.IgnorePath("/_content/**");
147+
});
143148

144149
app.UseHttpsRedirection();
145150

src/Arbiter.CommandQuery.Endpoints/RequestLoggingMiddleware.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Diagnostics;
33
using System.Text;
44

5+
using Arbiter.Services;
6+
57
using Microsoft.AspNetCore.Http;
68
using Microsoft.Extensions.Logging;
79
using Microsoft.Extensions.Options;
@@ -20,6 +22,7 @@ public partial class RequestLoggingMiddleware
2022
private readonly ILogger<RequestLoggingMiddleware> _logger;
2123
private readonly RequestLoggingOptions _options;
2224
private readonly ReadOnlyMemory<char>[] _allowedMimeTypes;
25+
private readonly List<GlobMatcher> _ignorePathMatchers;
2326

2427
/// <summary>
2528
/// Initializes a new instance of the <see cref="RequestLoggingMiddleware"/> class.
@@ -38,6 +41,9 @@ public RequestLoggingMiddleware(
3841

3942
// Pre-process MIME types into ReadOnlyMemory<char> for zero-allocation span comparisons
4043
_allowedMimeTypes = [.. _options.RequestBodyMimeTypes.Select(static t => t.AsMemory())];
44+
45+
// Pre-process ignore paths into GlobMatchers for efficient matching
46+
_ignorePathMatchers = [.. _options.IgnorePaths?.Select(path => new GlobMatcher(path)) ?? []];
4147
}
4248

4349
/// <summary>
@@ -47,12 +53,18 @@ public RequestLoggingMiddleware(
4753
/// <returns>A task that represents the asynchronous operation.</returns>
4854
public async Task InvokeAsync(HttpContext context)
4955
{
56+
var requestPath = context.Request.Path.Value;
57+
if (_ignorePathMatchers.Exists(m => m.IsMatch(requestPath)))
58+
{
59+
await _next(context).ConfigureAwait(false);
60+
return;
61+
}
62+
5063
// start timing
5164
var timestamp = Stopwatch.GetTimestamp();
5265

5366
// capture request details
5467
var requestMethod = context.Request.Method;
55-
var requestPath = context.Request.Path.Value;
5668

5769
// capture request body if configured
5870
var requestBody = await ReadBody(context.Request).ConfigureAwait(false);

src/Arbiter.CommandQuery.Endpoints/RequestLoggingOptions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,25 @@ public class RequestLoggingOptions
5555
/// The log level to use. Default is <see cref="LogLevel.Information"/>.
5656
/// </value>
5757
public LogLevel LogLevel { get; set; } = LogLevel.Information;
58+
59+
/// <summary>
60+
/// Gets or sets the list of request paths to ignore for logging.
61+
/// </summary>
62+
/// <remarks>
63+
/// Supports glob patterns for flexible path matching (e.g., "/health", "/api/*/status", "**.svg").
64+
/// </remarks>
65+
public IList<string>? IgnorePaths { get; set; }
66+
67+
/// <summary>
68+
/// Adds a request path to ignore for logging.
69+
/// </summary>
70+
/// <param name="globPattern">The path or glob pattern to ignore (e.g., "/health", "/api/*/status", "**.svg").</param>
71+
/// <returns>The current <see cref="RequestLoggingOptions"/> instance for method chaining.</returns>
72+
public RequestLoggingOptions IgnorePath(string globPattern)
73+
{
74+
IgnorePaths ??= [];
75+
IgnorePaths.Add(globPattern);
76+
77+
return this;
78+
}
5879
}

0 commit comments

Comments
 (0)