Created
August 3, 2019 13:56
-
-
Save emrekizildas/8c2f19b796397bdbfa02754dd1b758cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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