Skip to content

RequestLogger

Tore Nestenius edited this page Oct 24, 2024 · 10 revisions

HTTP(s) Request Logger

Overview

This tool lets you view all requests made to the Cloud Debugger application. It logs not only HTML page requests but also internal requests, authentication, health checks, and other requests.

The tool captures and logs the headers and body of each request and response.

Implementation Details

Two components handle the logging of request and response details:

  1. Custom HttpLogging Middleware
  2. Custom Middleware to Capture the Request Body

Custom HttpLogging Middleware

  • The middleware is based on the ASP.NET Core Http Logging middleware, but we converted it into a custom class library. To avoid any collisions, the namespace was changed to Microsoft.AspNetCore.MyHttpLogging.
  • We added custom code (found in the CustomCode folder) to log each request received. The middleware retains the latest 50 requests in memory.
  • All logs are written to a custom ILogger, named RequestLogger. From the Cloud Debugger, these logs can be queried and displayed on the screen.
  • The request and response bodies are truncated if they exceed 5000 characters.

Custom Request Body Capture Middleware

The UseRequestBodyCapture middleware is a helper middleware that captures the raw request body and stores it in the HttpContext.Items dictionary. This allows the custom HttpLogging middleware to access it later for logging.

Ignored Requests

To prevent the logs from becoming overloaded, the following requests are ignored:

  • /favicon.ico
  • /robots.txt
  • /requestlog/*

Additionally, requests for files with the following extensions are ignored: .css, .js, .png, .jpg, .jpeg, .gif, .ico, .svg, .woff, .woff2, .ttf, .eot, .map

This filtering is handled by the RequestLog class in the MyHttpLogging class library.

Clone this wiki locally