AspNetCoreRateLimit icon indicating copy to clipboard operation
AspNetCoreRateLimit copied to clipboard

Is there a way to log the client Ips ?

Open ashamandava opened this issue 5 years ago • 2 comments

Hi @cristipufu I wanted to log the IPs that are requesting data for testing purpose, can we do that ?

ashamandava avatar Sep 24 '20 14:09 ashamandava

Not sure if this question is related to AspNetCoreRateLimit, but you can always create your own custom middleware to log the IPs, similar to this example: https://docs.microsoft.com/en-us/aspnet/core/security/ip-safelist?view=aspnetcore-3.1

cristipufu avatar Sep 26 '20 17:09 cristipufu

@ashamandava and @cristipufu

This may not be exactly what you are looking for but if you are using Application Insights you can have it listen for the ILogger Information messages from the rate-limiting middleware. This can be done through appsettings.json.

e.g.

"Logging": { "LogLevel": { "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" }, "ApplicationInsights": { "LogLevel": { "Default": "Warning", "AspNetCoreRateLimit": "Information" } } }

In this example, we are telling Application Insights to record Warning (and above), except for when it comes to AspNetCoreRateLimit where we record Information (and above).

This lets you see the failure in Application Insights with a trace explaining why the request was blocked. I.e. what rule was applied.

g4mb10r avatar Oct 30 '20 23:10 g4mb10r