Skip to content

TNShehadeh/DMiddleware.HttpLogs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 

Repository files navigation

Request Logging Middleware

The Request Logging Middleware is a custom ASP.NET Core middleware designed to log detailed information about incoming HTTP requests and their corresponding responses. It provides functionality to capture various metrics, including CPU and memory usage, response times, and request details, enhancing monitoring and troubleshooting capabilities in your application.

Key Features

  • Request and Response Logging: Logs the HTTP method, path, timestamp, and response status, along with request and response bodies (configurable).
  • Performance Metrics: Tracks CPU usage, memory consumption, and request duration for each processed request.
  • Error Handling: Captures and logs detailed error information if exceptions occur during request processing.
  • Configurable Options: Easily configurable options to choose what data to log (request body, headers, response, etc.).
  • Database Integration: Utilizes a database context to persist log entries for further analysis.

Usage

appSettings.json

insert the following configuration into appSettings.json file:

{
    "HTTPLogConnection": {
        "DatabaseProvider": "", // SQL or PostgreSQL, the default is SQL
        "DefaultConnection": ""
    }
}

To use this middleware, configure it in your ASP.NET Core application’s startup/program.cs:

services.ConfigureDMiddlewareServices(options =>
{
    options.SaveRequestBody = true;
   options.SaveRequesterInfo = true;
   options.SaveRequestHeader = true;
   options.SaveResponse = true;
   options.LogTheLoggDashboard = false;
});

Then add the middleware to the request pipeline:

app.UseRequestLogging();

Accessing the Logs Dashboard

To access the logs dashboard, you can map the dashboard route by adding the following to your Configure method in Startup.cs or Program.cs:

app.MapDLoggerDashboard();

Once the dashboard is configured, you can access it via the following URL:

yourURL/DLogger/index.html

This middleware helps developers monitor application behavior and diagnose issues effectively, making it an essential tool for robust application logging.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published