DMiddleware 5.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DMiddleware --version 5.2.0                
NuGet\Install-Package DMiddleware -Version 5.2.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DMiddleware" Version="5.2.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DMiddleware --version 5.2.0                
#r "nuget: DMiddleware, 5.2.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DMiddleware as a Cake Addin
#addin nuget:?package=DMiddleware&version=5.2.0

// Install DMiddleware as a Cake Tool
#tool nuget:?package=DMiddleware&version=5.2.0                

Request Logging Middleware

Overview

The Request Logging Middleware is an ASP.NET Core middleware designed to capture detailed information about incoming HTTP requests and their corresponding responses. It logs various metrics such as CPU usage, memory consumption, request duration, and the success status of requests. Additionally, it can save the request body, request headers, and response body to a database for further analysis.

Features

  • Logging Request Information: Captures the request method, path, and associated controller and action names.
  • Performance Metrics: Measures CPU usage, memory consumption, and thread count differences during request processing.
  • Request and Response Logging: Optionally logs request bodies, headers, and responses based on configuration settings.
  • Error Handling: Logs any exceptions thrown during request processing along with detailed error information.

How It Works

  1. The middleware measures resource usage at the start of request processing.
  2. It reads and saves the request body and headers, while also replacing the response body stream to capture the response.
  3. After processing the request, it calculates performance metrics and logs the details to the database.
  4. The middleware can be configured to save specific pieces of information based on provided options.

Configuration

To use the middleware, configure it in the Startup.cs/program.cs file as follows:

services.ConfigureDMiddlewareServices(options ⇒ new PackageConfigurationOptions() { SaveRequestBody = true, SaveRequesterInfo = true, SaveRequestHeader = true, SaveResponse = true });

Then, add the middleware in the HTTP request pipeline:

app.UseRequestLogging();

Logging Structure

The following information is logged:

  • Request Logs: Includes method, path, timestamps, CPU/memory usage, request duration, and success status.
  • Response Logs: Contains the response body if configured to save.
  • Extra Request Info Logs: Captures request bodies and headers as JSON if configured to save.
  • Error Logs: Details any exceptions thrown during the processing of the request.

Conclusion

The Request Logging Middleware provides a robust solution for monitoring and logging HTTP requests in ASP.NET Core applications. It is particularly useful for debugging, performance monitoring, and ensuring the reliability of web applications.

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.5.0 36 11/21/2024
5.4.0 34 11/21/2024
5.3.0 78 11/15/2024
5.2.0 84 10/27/2024
5.1.3 76 10/26/2024
5.1.1 69 10/26/2024
5.1.0 65 10/26/2024
5.0.0 72 10/26/2024
2.1.0 84 10/22/2024
2.0.0 77 10/22/2024
1.0.0 104 10/20/2024