[ADMINAPI-1327] [ADMINAPI-1479] fix: Enhance audit logging middleware to capture tenant information - #417
Merged
Merged
Conversation
…nd response status codes - Updated AuditActionLoggingMiddleware to read tenant from HttpContext.Items for accurate logging. - Modified IAuditEventRecorder and AuditEventRecorder to accept tenant configuration. - Adjusted middleware registration order in Program.cs to ensure correct status code logging. - Improved documentation to clarify middleware behavior and tenant resolution.
Contributor
Test Results 15 files 15 suites 1m 32s ⏱️ Results for commit 068718f. |
DavidJGapCR
approved these changes
Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request makes significant improvements to how audit logging middleware is ordered and how tenant context is resolved for audit events, especially in multitenant scenarios. The changes ensure that audit logs always capture the correct HTTP status code and tenant information, even when requests are short-circuited by authentication or authorization middleware. The documentation is also updated to explain these changes and their rationale.
Middleware ordering and audit logging improvements:
AuditActionLoggingMiddlewareis now registered as the outermost middleware inProgram.cs, ensuring it observes the final response status code after all error-handling middleware has run. This guarantees accurate status codes in audit logs, including those for authorization failures (401/403). [1] [2]HttpContext.Items(populated byTenantResolverMiddleware) instead of relying on theAsyncLocalcontext, which may revert before audit logging occurs. This ensures the correct tenant is associated with each audit event. [1] [2] [3] [4]Audit event recording and interface changes:
IAuditEventRecorder.Recordmethod and its implementation now accept an explicitTenantConfiguration? tenantparameter, defaulting to theAsyncLocalcontext only if not provided. [1] [2] [3]Documentation updates:
audit-logging.mdand2026-07-28-audit-trail-logging.md) is updated to clarify:HttpContext.Itemsrather than the ambient context. [1] [2] [3] [4] [5]Codebase and dependency updates:
These changes ensure robust and accurate audit logging in multitenant environments, with clear documentation for future maintainers.