Skip to content
Julian Verdurmen edited this page Jun 9, 2016 · 4 revisions

Log HTTP calls

How to log all http calls with ASP.NET MVC

public class LogHttpRequestAttribute : ActionFilterAttribute
{
    private static Logger _logger = LogManager.GetCurrentClassLogger();

    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        _logger.Debug("action executing");

        base.OnActionExecuting(filterContext);
    }
}

usage:

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
 
    // Register global filter
    GlobalFilters.Filters.Add(new LogHttpRequestAttribute ());
    

}

For request URL, use for example ${aspnet-request:serverVariable=HTTP_URL}, See wiki