fix(logging): fail-closed bearer redaction; hoist per-request logger creation

This commit is contained in:
Joseph Doherty
2026-08-15 12:17:27 -04:00
parent e2ac5d117a
commit ca34a2d65d
4 changed files with 182 additions and 73 deletions
@@ -24,12 +24,16 @@ public static class GatewayRequestLoggingMiddlewareExtensions
{
ArgumentNullException.ThrowIfNull(app);
// Resolved once at registration: the logger is keyed by category, not by request, so the
// per-request DI resolve and logger-factory lock bought nothing.
ILogger logger = app.ApplicationServices
.GetRequiredService<ILoggerFactory>()
.CreateLogger("MxGateway.Request");
return app.Use(async (context, next) =>
{
ILogger logger = context.RequestServices
.GetRequiredService<ILoggerFactory>()
.CreateLogger("MxGateway.Request");
// Scope construction is deliberately unconditional: gating it on IsEnabled would drop
// scope state for providers (and scope consumers) registered after startup.
using IDisposable? scope = logger.BeginGatewayScope(new GatewayLogScope(
SessionId: ReadHeader(context, SessionIdHeaderName),
WorkerProcessId: ReadInt32Header(context, WorkerProcessIdHeaderName),