You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enrich logs with client IP, Correlation Id and HTTP request headers.
3
3
4
4
Install the _Serilog.Enrichers.ClientInfo_[NuGet package](https://www.nuget.org/packages/Serilog.Enrichers.ClientInfo/)
5
5
@@ -16,7 +16,8 @@ Apply the enricher to your `LoggerConfiguration` in code:
16
16
```csharp
17
17
Log.Logger=newLoggerConfiguration()
18
18
.Enrich.WithClientIp()
19
-
.Enrich.WithClientAgent()
19
+
.Enrich.WithCorrelationId()
20
+
.Enrich.WithRequestHeader("Header-Name1")
20
21
// ...other configuration...
21
22
.CreateLogger();
22
23
```
@@ -27,22 +28,30 @@ or in `appsettings.json` file:
27
28
"Serilog": {
28
29
"MinimumLevel": "Debug",
29
30
"Using": [ "Serilog.Enrichers.ClientInfo" ],
30
-
"Enrich": [ "WithClientIp", "WithClientAgent"],
31
+
"Enrich": [
32
+
"WithClientIp",
33
+
"WithCorrelationId",
34
+
{
35
+
"Name": "WithRequestHeader",
36
+
"Args": { "headerName": "Cache-Control"}
37
+
}
38
+
],
31
39
"WriteTo": [
32
40
{ "Name": "Console" }
33
41
]
34
42
}
35
43
}
36
44
```
37
45
38
-
The `WithClientIp()` enricher will add a `ClientIp` property and the `WithClientAgent()` enricher will add a `ClientAgent` property to produced events.
46
+
---
39
47
40
-
For `ClientIp` enricher you can configure the `X-forwarded-for` header if the proxy server uses a different header to forward IP address.
48
+
For `ClientIp` enricher you can configure the `x-forwarded-for` header if the proxy server uses a different header to forward the IP address.
0 commit comments