DMiddleware 5.2.0
See the version list below for details.
dotnet add package DMiddleware --version 5.2.0
NuGet\Install-Package DMiddleware -Version 5.2.0
<PackageReference Include="DMiddleware" Version="5.2.0" />
paket add DMiddleware --version 5.2.0
#r "nuget: DMiddleware, 5.2.0"
// 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
- The middleware measures resource usage at the start of request processing.
- It reads and saves the request body and headers, while also replacing the response body stream to capture the response.
- After processing the request, it calculates performance metrics and logs the details to the database.
- 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 | Versions 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. |
-
net5.0
- JsonConverter.Newtonsoft.Json (>= 0.7.0)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Routing (>= 2.2.2)
- Microsoft.EntityFrameworkCore (>= 5.0.17)
- Microsoft.EntityFrameworkCore.SqlServer (>= 5.0.17)
- Microsoft.Extensions.Configuration (>= 5.0.0)
- Microsoft.Extensions.Configuration.Json (>= 5.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 5.0.0)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 5.0.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.