Enrich Serilog log events with properties from the current HttpContext.
To use the enricher, first install the NuGet package:
Install-Package Serilog.Enrichers.HttpContextInfo
Then, apply the enricher to your LoggerConfiguration
:
Log.Logger = new LoggerConfiguration()
.Enrich.WithRequest()
// ...other configuration...
.CreateLogger();
The WithRequest()
enricher will add the current HttpRequest
properties to produced events.
The package includes:
WithRequest()
- adds theHttpRequest
from the current HttpContext.WithResponse()
- adds theHttpResponse
from the current HttpContext.