Beispiel #1
0
        public async Task Invoke(HttpContext httpContext, IApiLogRepository apiLogRepository)
        {
            Stopwatch watch = new Stopwatch();
            var       now   = _clock.UtcNow.UtcDateTime;

            watch.Start();
            await _next(httpContext);

            watch.Stop();

            var user = httpContext.User.ParseAllClaims();

            var log = new ApiLog();

            log.DurationMs   = (int)watch.ElapsedMilliseconds;
            log.Route        = httpContext.GetRouteData().Values["controller"] + "." + httpContext.GetRouteData().Values["action"];
            log.StartedAt    = now;
            log.UserId       = user != null ? (int?)user.User.Id : null;
            log.Verb         = httpContext.Request.Method;
            log.ResponseCode = httpContext.Response.StatusCode;
            log.QueryString  = httpContext.Request.QueryString.ToString();

            try
            {
                await apiLogRepository.InsertApiLog(log);
            }
            catch (Exception ex)
            {
            }
        }
 public CommonDbResponse InsertApiLog(ApiLogCommon apiLog)
 {
     return(_api.InsertApiLog(apiLog));
 }