コード例 #1
0
        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);
        }
コード例 #2
0
            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();
            }
コード例 #3
0
            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);
            }