Skip to content

Modernize structured logging and redact HTTP request/response logs #1337

Description

@StuartFerguson

Summary

Modernize Shared.Logger and HTTP request/response logging in Shared.Middleware to emit structured, correlation-friendly events while reducing the risk of logging sensitive data.

Changes

Shared.Logger

  • Add message-template overloads with arguments across log levels, including exception-aware error and critical logging.
  • Emit NLog events with structured properties for event ID, UTC timestamp, service name, severity, tenant and merchant IDs, correlation ID, and distributed trace/span IDs when available.
  • Keep existing message-only APIs available with obsolescence guidance, and remove the Microsoft.Extensions.Logging adapter in favor of the NLog implementation.
  • Add a sample project demonstrating logger configuration and use.

Shared.Middleware

  • Emit structured HTTP request and response events with request ID, method/path/query, status code, elapsed time, headers, body capture status, and health-check classification.
  • Redact configured sensitive query, header, JSON, form, and XML values; filter headers through configurable allowlists.
  • Bound request and response body capture by configurable byte limits and report unsupported, oversized, or failed captures without logging the body.
  • Preserve request/response stream behavior and classify health-check paths case-insensitively.

Acceptance criteria

  • Logger events retain message-template arguments and include available tenant, correlation, and trace context.
  • Middleware logs only allowlisted headers and redacts configured sensitive values in supported body formats and query parameters.
  • Body capture limits and capture-status outcomes are configurable and represented in structured events.
  • The sample project demonstrates the updated logger API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions