ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.38k stars 1.64k forks source link

Ability to have RemoteIpAddress in logs #1008

Open NicolasPrivatViseo opened 5 years ago

NicolasPrivatViseo commented 5 years ago

New Feature

Add RemoteIpAddress in log message (IP of caller)

Motivation for New Feature

Current log message is _logger.Log[Level]("requestId: {requestId}, previousRequestId: {previousRequestId}, message: {message}", requestId, previousRequestId, message);

New log message could be _logger.Log[Level]("remoteIpAddress: {remoteIpAddress}, requestId: {requestId}, previousRequestId: {previousRequestId}, message: {message}",remoteIpAddress, requestId, previousRequestId, message);

The IP address is a security element that needs to be traced in some cases for security/analysis purposes.

Solutions tried

Forward IP in header or middleware injection is not suitable in this case because we need the information in the logs generated by Ocelot.

A have tried locally to add IP in log message (class AspDotNetLogger.cs), but the HttpContextAccessor is not accessible in the _scopedDataRepository variable, which is an instance of HttpDataRepository. I cannot get it without modification of IRequestScopedDataRepository that would have implications I am not aware of.

NicolasPrivatViseo commented 5 years ago

@TomPallister Any thoughts on that feature request ?

raman-m commented 7 months ago

Feature

Did you read the docs?

In order to use custom logging you have to

Good luck!

raman-m commented 7 months ago

@ggnaegi Your opinion regarding force writing HttpContext.Connection.RemoteIpAddress into the logs by default OcelotLogger implementation in Ocelot?

Currently we use RemoteIpAddress in a limited number of Ocelot features: Search And there is no unified logic to detect remote host...