Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created September 4, 2018 20:58
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 explorer14/b6e1b9d8a7c06fb4da25a3002110ffa4 to your computer and use it in GitHub Desktop.
Save explorer14/b6e1b9d8a7c06fb4da25a3002110ffa4 to your computer and use it in GitHub Desktop.
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