Exemplo n.º 1
0
        public async Task Invoke(HttpContext context)
        {
            if (context.Request.Path.HasValue && context.Request.Path.Value.Contains("/api/"))
            {
                APILogEntity logEntity = new APILogEntity();

                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();

                await LogRequest(context, logEntity);

                await LogResponseAndInvokeNext(context, logEntity);

                stopwatch.Stop();

                logEntity.ResponseTime = stopwatch.Elapsed;

                _logService.SaveLog(logEntity);
            }
            else
            {
                await _next(context);
            }
        }