public async Task Invoke(HttpContext context) { var sw = Stopwatch.StartNew(); try { AsyncLogger.StartRequestLog(context.TraceIdentifier, $"=> Starting request ${context.TraceIdentifier}"); await _next.Invoke(context); } catch (Exception e) { AsyncLogger.LogException(e.Message, e); } finally { sw.Stop(); Debug.WriteLine(AsyncLogger.EndRequestLog($"<= Ending request ${context.TraceIdentifier}. Total duration: {sw.ElapsedMilliseconds} ms")); } }