PortiaNet.HealthCheck.Reporter
1.0.0
See the version list below for details.
dotnet add package PortiaNet.HealthCheck.Reporter --version 1.0.0
NuGet\Install-Package PortiaNet.HealthCheck.Reporter -Version 1.0.0
<PackageReference Include="PortiaNet.HealthCheck.Reporter" Version="1.0.0" />
paket add PortiaNet.HealthCheck.Reporter --version 1.0.0
#r "nuget: PortiaNet.HealthCheck.Reporter, 1.0.0"
// Install PortiaNet.HealthCheck.Reporter as a Cake Addin #addin nuget:?package=PortiaNet.HealthCheck.Reporter&version=1.0.0 // Install PortiaNet.HealthCheck.Reporter as a Cake Tool #tool nuget:?package=PortiaNet.HealthCheck.Reporter&version=1.0.0
<img src="https://user-images.githubusercontent.com/11803924/159634426-45568864-0568-441c-9d0b-a28756f42f9f.png" width="400">
What is PortiaNet.HealthCheck.Reporter?
PortiaNet.HealthCheck.Reporter is a middleware for .Net web applications (WebAPI and MVC) which collects all required information about the income requests on the server, then delivers them to a service to be saved or analyzed.
The following project has the core functionality of the health check which only collects the information and delivers them to a registered service with the type of IHealthCheckReportService.
The information which this middleware provides are as follows:
- Client IP Address
- User Identity (if using authentication middleware)
- Host Address which has received the request (Usefull for the load balancing)
- Request Method Type (Get, Put, Push, Patch, Delete)
- API Path which has been called
- Query String
- Full User Agent Information
- Duration time which the API call took
- Success Result of the API (To check if API throws any unknown or unhandled exception)
<img src="https://user-images.githubusercontent.com/11803924/159649606-9b56f148-f28f-42f7-be1b-e0d15c41d1a7.png" width="600">
Installation
You can install this tool from Nuget using Package Manager Console:
PM> Install-Package PortiaNet.HealthCheck.Reporter
How do I get started?
- You need a service in your repository to receive the reports from the middleware, then create a simple one and inherit it from IHealthCheckReportService.
public class HealthCheckReportServiceImpl : IHealthCheckReportService
{
public Task SaveAPICallInformationAsync(RequestDetail requestDetail)
{
// Using this method, you can save all collected information in a cloud, local, or third-party database.
// It is highly recommended to save the tracked information in another database than the main one due to decrease the performance issue
}
}
- The service should be added to the DI in the Configuration section.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransient<IHealthCheckReportService, HealthCheckReportServiceImpl>();
- Add the middleware to the pipeline. Keep in mind to add it after
Authentication
middleware (if any, otherwise the logged-in user's identity will be always empty). It is recommended to put this middleware as the last one to have accurate API duration information.
var app = builder.Build();
...
app.UseAuthentication();
...
app.UseHealthCheck();
...
How does it work?
When the HealthCheck middleware receives the request, it checks the attributes of the target API, and if it had the HealthCheckIgnoreAttribute
attribute then the request won't be tracked.
In the next step, the middleware forwards the request to the next ones in the pipeline. This middleware catches all exceptions which may get thrown by the next middlewares, and if the thrown exception wasn't a subtype of IHealthCheckKnownException
, then it will mark the request track entity with an error. Then rethrows the exception to be handled by the previous middlewares (e.g. global exception handler). But before going back to the previous middleware, it sends all gathered information to the SaveAPICallInformationAsync
method of the injected IHealthCheckReportService
service.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.AspNetCore.Routing.Abstractions (>= 2.2.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on PortiaNet.HealthCheck.Reporter:
Package | Downloads |
---|---|
PortiaNet.HealthCheck.Writer.SQLServer
This package is the writer for PortiaNet.HealthCheck.Reporter library that saves the reports in an MS SQL Server Database. |
|
PortiaNet.HealthCheck.Writer.MongoDB
This package is the writer for PortiaNet.HealthCheck.Reporter library that saves the reports in a MongoDB Database. |
|
PortiaNet.HealthCheck.Writer.HTTP
This package is the writer for PortiaNet.HealthCheck.Reporter library that sends the reports to the REST APIs to be saved in another system. |
GitHub repositories
This package is not used by any popular GitHub repositories.