Ocelot icon indicating copy to clipboard operation
Ocelot copied to clipboard

Ability to have RemoteIpAddress in logs

Open NicolasPrivatViseo opened this issue 5 years ago • 3 comments

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 avatar Sep 06 '19 09:09 NicolasPrivatViseo