コード例 #1
0
        /// <summary>
        /// Process an individual request and response.
        /// </summary>
        /// <param name="context">The <see cref="IOwinContext"/></param>
        /// <returns><see cref="Task"/></returns>
        public override async Task Invoke(IOwinContext context)
        {
            Guid requestId = Guid.Empty;

            try
            {
                requestId = await _logHandler.LogRequestAsync(context);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
            }

            var stopWatch = new Stopwatch();

            stopWatch.Start();

            await _next.Invoke(context);

            var elapsedMilliseconds = stopWatch.ElapsedMilliseconds;

            stopWatch.Stop();

            try
            {
                await _logHandler.LogResponseAsync(context, requestId, elapsedMilliseconds);
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message);
            }
        }