Skip to content

Instantly share code, notes, and snippets.

@emrekizildas
Created August 3, 2019 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emrekizildas/8c2f19b796397bdbfa02754dd1b758cd to your computer and use it in GitHub Desktop.
Save emrekizildas/8c2f19b796397bdbfa02754dd1b758cd to your computer and use it in GitHub Desktop.
public override void OnActionExecuted(ActionExecutedContext context)
{
System.Net.IPAddress ipAddress = context.HttpContext.Connection.RemoteIpAddress;
string controllerName = ((ControllerActionDescriptor)context.ActionDescriptor).ControllerName;
string actionName = ((ControllerActionDescriptor)context.ActionDescriptor).ActionName;
if (context.Exception == null)
{
Log
.ForContext("IPAddress", ipAddress)
.ForContext("ControllerName", controllerName)
.ForContext("ActionName", actionName)
.Information($"IP Address: {ipAddress} - Controller Name: {controllerName} - Action Name: {actionName}");
}
else
{
Log
.ForContext("IPAddress", ipAddress)
.ForContext("ControllerName", controllerName)
.ForContext("ActionName", actionName)
.ForContext("ErrorMessage", context.Exception.Message)
.Error($"IP Address: {ipAddress} - Controller Name: {controllerName} - Action Name: {actionName}");
}
base.OnActionExecuted(context);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment