Garnet.Serilog.Enricher.HttpContext
0.0.4
See the version list below for details.
dotnet add package Garnet.Serilog.Enricher.HttpContext --version 0.0.4
NuGet\Install-Package Garnet.Serilog.Enricher.HttpContext -Version 0.0.4
<PackageReference Include="Garnet.Serilog.Enricher.HttpContext" Version="0.0.4" />
paket add Garnet.Serilog.Enricher.HttpContext --version 0.0.4
#r "nuget: Garnet.Serilog.Enricher.HttpContext, 0.0.4"
// Install Garnet.Serilog.Enricher.HttpContext as a Cake Addin #addin nuget:?package=Garnet.Serilog.Enricher.HttpContext&version=0.0.4 // Install Garnet.Serilog.Enricher.HttpContext as a Cake Tool #tool nuget:?package=Garnet.Serilog.Enricher.HttpContext&version=0.0.4
Garnet Serilog HttpContext Enricher
Serilog comprehensive HttpContext enrichers like request body, response body, request and response headers, user claims, ...
Installation
dotnet add package Garnet.Serilog.Enricher.HttpContext
List of Enrichers
- Request Body
- Request Headers
- Request Url
- Response Body
- Response Headers
- User Claims
- Custom Property<small>: Enrich with any information from HttpContext</small>
- Custom Property With Cache<small>: Like Custom Property with caching the result</small>
Usage
First, enrichers and their requirements need to be registered
services.AddAllGarnetHttpContextEnrichers() //Add all enrichers with default configuration
// ---OR---
//You can add each individual enricher
services.AddGarnetRequestBodyEnricher();
services.AddGarnetRequestHeadersEnricher();
services.AddGarnetRequestUrlEnricher();
services.AddGarnetResponseBodyEnricher();
services.AddGarnetResponseHeadersEnricher();
services.AddGarnetUserClaimsEnricher();
Other overloads of these methods can be used to set configuration or read configuration from appsettings
.
For RequestBody and ResponseBody enrichers to work you need to use their ASP middlewares
app //IApplicantBuilder
.UseGarnetRequestBodyEnricherMiddleware()
.UseGarnetResponseBodyEnricherMiddleware()
...;
The order of using middlewares is important to have proper log information. For example if you have a middleware that produces custom responses on exception occurrence and you want to log the exact response, you should register the GarnetResponseBody middleware before that. More information
Now let Serilog
to use Garnet enrichers all at once or one by one as you need.
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog((context, services, configuration) => configuration
.ReadFrom.Configuration(context.Configuration)
.ReadFrom.Services(services)
.Enrich.FromLogContext()
.Enrich.WithAllGarnetHttpContextEnrichers(serviceProvider) // <---
// ---OR---
.Enrich.WithGarnetRequestBody(serviceProvider)
.Enrich.WithGarnetRequestHeaders(serviceProvider)
.Enrich.WithGarnetRequestUrl(serviceProvider)
.Enrich.WithGarnetResponseBody(serviceProvider)
.Enrich.WithGarnetResponseHeaders(serviceProvider)
.Enrich.WithGarnetUserClaims(serviceProvider);
// --------
.WriteTo.Console())
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
You can use custom enrichers to add more information to LogEvent
from HttpContext
...
.Enrich.With(new GarnetHttpContextCustomPropertyEnricher("ResponseStatusCode",
serviceProvider,
httpContext => httpContext.Response.StatusCode)) //<--- provide result
...;
// ---OR---
// The following custom enricher caches the provided result for further events in a same instanse of the HttpContext (in a same incoming request)
...
.Enrich.With(new GarnetHttpContextCustomPropertyEnricherWithCache("RequestMethod",
serviceProvider,
httpContext => httpContext.Request.Method)); //<--- provide result
...;
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Microsoft.AspNetCore.Http (>= 2.2.0)
- Microsoft.AspNetCore.Http.Extensions (>= 2.2.0)
- Microsoft.Extensions.Configuration.Binder (>= 5.0.0)
- Serilog (>= 2.10.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.