Beispiel #1
0
        public void OnActionExecuted(ActionExecutedContext context)
        {
            var httpContext = context.HttpContext;
            var stopwach    = httpContext.Items["StopwachKey"] as Stopwatch;

            stopwach.Stop();

            var controller = context.Controller as ControllerBase;

            logmodel.ResultValue = JsonConvert.SerializeObject(context.Result);
            logmodel.InputTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var time = stopwach.Elapsed;

            logmodel.ExecTime = time.TotalSeconds.ToString();
            if (time.TotalSeconds > 5)
            {
                //添加日志
                Log4NetProvider.Info(context.ActionDescriptor, JsonConvert.SerializeObject(logmodel));
            }
        }