Net.CrossCutting.RequestLogger 1.0.4

dotnet add package Net.CrossCutting.RequestLogger --version 1.0.4
NuGet\Install-Package Net.CrossCutting.RequestLogger -Version 1.0.4
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="Net.CrossCutting.RequestLogger" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Net.CrossCutting.RequestLogger --version 1.0.4
#r "nuget: Net.CrossCutting.RequestLogger, 1.0.4"
#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 Net.CrossCutting.RequestLogger as a Cake Addin
#addin nuget:?package=Net.CrossCutting.RequestLogger&version=1.0.4

// Install Net.CrossCutting.RequestLogger as a Cake Tool
#tool nuget:?package=Net.CrossCutting.RequestLogger&version=1.0.4

Net.CrossCutting.RequestLogger

Handle Cross-Cutting conserns via the power of Asp.net-core middelwares.

RequestLogger make it possible to log each http request and it related response to multiple data source (DB or file for example).

At the beginning you need to config RequestLogger, this is requierd because we need to fetch some dynamic settings at start point. To achieve that add a new json properties named RequestLog to your appseting.josn file.

{
  "RequestLogger": {
    "Status": true,
    //file,sqlserver
    "Provider": "sqlserver",
    "FilePath": "logs/requests/reqlog-.txt",
    "SqlServerConnectionString": "Data Source=SQL-SRV\\SQL2017;Initial Catalog=Logs;User ID=sa;Password=admin",
    "SqlServerTableName": "RequestLog"
  }
}

Then edit your startup and ConfigureServices methods (composition root of your Dependency Injection Startup.cs file by default) as below.

private RequestLogSetting requestLogSetting;

public Startup(IConfiguration configuration)
{
    //...
    requestLogSetting = Configuration.GetSection("RequestLogger").Get<RequestLogSetting>();
    //...
}

public void ConfigureServices(IServiceCollection services)
{
    //...
    services.AddSingleton<IRequestLogSetting>(requestLogSetting);
    //...
}

Finally edit your Configure method. This tell .net core runtime to inject RequestLogger middelware to its pipeline.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    //Sample 1: Log all recieved requests
    appBuilder.UseRequestLoggerMiddleware();    
    //...
}
}

Also you can filter the routing of middelware as you want like the following example. In this example the middelware logs all recieved requests when incomming http requests started with '/api'.

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseWhen(context => context.Request.Path.StartsWithSegments("/api"), appBuilder =>
    {
        appBuilder.UseRequestLoggerMiddleware();
    });
    //...
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  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. 
.NET Core netcoreapp2.1 is compatible.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 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
1.0.4 1,296 10/29/2018
1.0.3 1,217 10/29/2018
1.0.1 1,252 10/29/2018