Ejemplo n.º 1
0
        public async Task InvokeAsync(HttpContext context)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            var CorrelationId = context.AddCorrelationId();
            var method        = context.Request.Method;
            var requestPath   = context.Request.Path.ToString();

            try
            {
                await _next(context);

                var elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.LogInformation("Success for {@method} {@requestPath} with {@CorrelationId} in {@elapsedTime} millis", method, requestPath, CorrelationId, elapsedTime);
            }
            catch (Exception exception)
            {
                var elapsedTime = stopwatch.ElapsedMilliseconds;
                _logger.LogInformation("Exception {@exception.Message} for {@method} {@requestPath} with {@CorrelationId} in {@elapsedTime} millis", exception.Message, method, requestPath, CorrelationId, elapsedTime);
                Console.WriteLine(exception);
                throw;
            }
        }