public async Task InvokeAsync(HttpContext httpContext) { var flowId = FlowIdHelper.SetFlowId(httpContext.Request.Path.Value); _logService = (ILogService)httpContext.RequestServices.GetService(typeof(ILogService)); _logService.Info("{FlowStatus} middleware operation {FlowId}", FlowStatus.Start, flowId); await _next(httpContext); _logService.Info("{FlowStatus} middleware operation {FlowId}", FlowStatus.End, flowId); }
public override void OnActionExecuting(ActionExecutingContext context) { var flowId = FlowIdHelper.SetFlowId(context.HttpContext.Request.Path.Value); _logService.Info(new { FlowStatus = FlowStatus.Start.ToString(), FlowId = flowId, Method = context.ActionDescriptor.DisplayName }); _logService.Info("Another way of log with properties {FlowStatus} {FlowId} {Method}", FlowStatus.Start.ToString(), flowId, context.ActionDescriptor.DisplayName); context.ActionDescriptor.Properties[context.ActionDescriptor.DisplayName] = Stopwatch.StartNew(); }
public override void OnActionExecuted(ActionExecutedContext context) { var flowId = FlowIdHelper.SetFlowId(context.HttpContext.Request.Path.Value); var stopWatch = (Stopwatch)context.ActionDescriptor.Properties [context.ActionDescriptor.DisplayName]; stopWatch.Stop(); _logService.Info(new { FlowStatus = FlowStatus.End.ToString(), FlowId = flowId, Method = context.ActionDescriptor.DisplayName, ExecutionTimeElapsed = stopWatch.ElapsedMilliseconds }); _logService.Info("Another way of log with properties {FlowStatus} {FlowId} {Method} {ExecutionTimeElapsed}", FlowStatus.End.ToString(), flowId, context.ActionDescriptor.DisplayName, stopWatch.ElapsedMilliseconds); }