Created
September 4, 2018 20:58
-
-
Save explorer14/b6e1b9d8a7c06fb4da25a3002110ffa4 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 class ControllerActionProfilingFilter : IActionFilter | |
{ | |
private Stopwatch stopwatch; | |
public void OnActionExecuted(ActionExecutedContext context) | |
{ | |
stopwatch.Stop(); | |
Log.Logger.Information( | |
$"Action {context.ActionDescriptor.DisplayName} " + | |
$"executed in {stopwatch.Elapsed.ToString()} " + | |
$"RequestId: {context.HttpContext.TraceIdentifier}{Environment.NewLine}"); | |
} | |
public void OnActionExecuting(ActionExecutingContext context) | |
{ | |
Log.Logger.Information( | |
$"Profiling {(context.Controller as Controller).Request.Path} " + | |
$"RequestId: {context.HttpContext.TraceIdentifier}{Environment.NewLine}"); | |
stopwatch = Stopwatch.StartNew(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment