Created
July 3, 2014 13:33
-
-
Save khellang/fa6a94abed6b791d997e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static MidFunc Tracing(ITracer tracer) | |
{ | |
if (tracer == null) throw new ArgumentNullException("tracer"); | |
tracer = new SafeTracer(tracer); | |
return next => async env => | |
{ | |
if (!tracer.IsEnabled) | |
{ | |
await next(env); | |
} | |
else | |
{ | |
tracer.Trace("Request Start"); | |
var stopWatch = Stopwatch.StartNew(); | |
await next(env); | |
stopWatch.Stop(); | |
if (tracer.Filters.All(filter => filter.Invoke(env))) | |
{ | |
foreach (var item in env) | |
{ | |
tracer.Trace(item.Key, item.Value); | |
} | |
} | |
tracer.Trace(string.Format("Request completed in {0} ms", stopWatch.ElapsedMilliseconds)); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment