-
Notifications
You must be signed in to change notification settings - Fork 166
Log HTTP calls
Rolf Kristensen edited this page Oct 8, 2022
·
4 revisions
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 ());
}
To log the URL, then include ${aspnet-request:serverVariable=HTTP_URL}
in the NLog Target Layout. See also NLog.Web LayoutRenderers
See also HTTP Request Logging using NLogRequestLoggingModule
.
For general docs, check https://github.com/NLog/NLog/wiki