PortiaNet.HealthCheck.Reporter 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PortiaNet.HealthCheck.Reporter --version 1.0.1                
NuGet\Install-Package PortiaNet.HealthCheck.Reporter -Version 1.0.1                
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="PortiaNet.HealthCheck.Reporter" Version="1.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PortiaNet.HealthCheck.Reporter --version 1.0.1                
#r "nuget: PortiaNet.HealthCheck.Reporter, 1.0.1"                
#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 PortiaNet.HealthCheck.Reporter as a Cake Addin
#addin nuget:?package=PortiaNet.HealthCheck.Reporter&version=1.0.1

// Install PortiaNet.HealthCheck.Reporter as a Cake Tool
#tool nuget:?package=PortiaNet.HealthCheck.Reporter&version=1.0.1                

<img src="https://user-images.githubusercontent.com/11803924/159634426-45568864-0568-441c-9d0b-a28756f42f9f.png" width="400">

Nuget

What is PortiaNet.HealthCheck.Reporter?

alternate text is missing from this package README image 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?

  1. 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
    }
}
  1. The service should be added to the DI in the Configuration section.
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddTransient<IHealthCheckReportService, HealthCheckReportServiceImpl>();
  1. 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.

chart drawio

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.3.0 273 2/1/2024
1.2.0 640 12/26/2022
1.1.0 912 7/7/2022
1.0.4 647 5/23/2022
1.0.3 896 4/16/2022
1.0.2 767 4/14/2022
1.0.1 770 4/10/2022
1.0.0 418 4/5/2022