Adds timestamp in accordance with hosting example, as well as duration
This commit is contained in:
parent
5ecba206ad
commit
f387d04af1
|
|
@ -28,9 +28,18 @@ namespace Microsoft.AspNetCore.MiddlewareAnalysis
|
||||||
|
|
||||||
public async Task Invoke(HttpContext httpContext)
|
public async Task Invoke(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
|
var startTimestamp = Stopwatch.GetTimestamp();
|
||||||
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting"))
|
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting"))
|
||||||
{
|
{
|
||||||
_diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId });
|
_diagnostics.Write(
|
||||||
|
"Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting",
|
||||||
|
new
|
||||||
|
{
|
||||||
|
name = _middlewareName,
|
||||||
|
httpContext = httpContext,
|
||||||
|
instanceId = _instanceId,
|
||||||
|
timestamp = startTimestamp,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
|
@ -39,14 +48,35 @@ namespace Microsoft.AspNetCore.MiddlewareAnalysis
|
||||||
|
|
||||||
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished"))
|
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished"))
|
||||||
{
|
{
|
||||||
_diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId });
|
var currentTimestamp = Stopwatch.GetTimestamp();
|
||||||
|
_diagnostics.Write(
|
||||||
|
"Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished",
|
||||||
|
new
|
||||||
|
{
|
||||||
|
name = _middlewareName,
|
||||||
|
httpContext = httpContext,
|
||||||
|
instanceId = _instanceId,
|
||||||
|
timestamp = currentTimestamp,
|
||||||
|
duration = currentTimestamp - startTimestamp,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException"))
|
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException"))
|
||||||
{
|
{
|
||||||
_diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId, exception = ex });
|
var currentTimestamp = Stopwatch.GetTimestamp();
|
||||||
|
_diagnostics.Write(
|
||||||
|
"Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException",
|
||||||
|
new
|
||||||
|
{
|
||||||
|
name = _middlewareName,
|
||||||
|
httpContext = httpContext,
|
||||||
|
instanceId = _instanceId,
|
||||||
|
timestamp = currentTimestamp,
|
||||||
|
duration = currentTimestamp - startTimestamp,
|
||||||
|
exception = ex,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue