I am trying to create a [LoggedApiCall] filter for a Get() on an ApiController
According to this: ASP.NET Web API ActionFilter example
I have created a System.Web.HttpFilters.ActionFilterAttribute.
The override allows for OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
I cannot seem to find a way to get the IP of the caller from the HttpActionExecutedContext
Perhaps I am going about logging every API call the wrong way?
We use the following filter which we add to
HttpConfiguration.Filters. Some code:We use log4net, you can replace the
ILogimplementation with whatever you see fit.ILog.DebugTimingis just an extension method that uses a Stopwatch to get elapsed time for each call.Edit:
This post Get the IP address of the remote host has details on how to get the IP address of the remote caller.
Cheers,
Dean