fix(logging): fail-closed bearer redaction; hoist per-request logger creation
This commit is contained in:
+8
-4
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user