public class LogIPAttribute : TypeFilterAttribute
{
public LogIPAttribute() : base(typeof(LogIPFilterImpl))
{
}
public class LogIPFilterImpl(ILogger<LogIPFilterImpl> logger) : IActionFilter
{
public void OnActionExecuting(ActionExecutingContext context)
{
var ipAddress = context.HttpContext.Connection.RemoteIpAddress?.ToString();
var httpMethod = context.HttpContext.Request.Method;
logger.LogInformation($"Accessed IP: {ipAddress}, Method: {httpMethod}");
}
public void OnActionExecuted(ActionExecutedContext context)
{
}
}
}