Addition of InstanceId to the messages being published.

This commit is contained in:
Anthony van der Hoorn 2016-03-18 13:13:38 -07:00 committed by Chris R
parent 0a444088c9
commit 23976ebd53
1 changed files with 4 additions and 3 deletions

View File

@ -10,6 +10,7 @@ namespace Microsoft.AspNetCore.MiddlewareAnalysis
{ {
public class AnalysisMiddleware public class AnalysisMiddleware
{ {
private readonly Guid _instanceId = Guid.NewGuid();
private readonly RequestDelegate _next; private readonly RequestDelegate _next;
private readonly DiagnosticSource _diagnostics; private readonly DiagnosticSource _diagnostics;
private readonly string _middlewareName; private readonly string _middlewareName;
@ -29,7 +30,7 @@ namespace Microsoft.AspNetCore.MiddlewareAnalysis
{ {
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 }); _diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId });
} }
try try
@ -38,14 +39,14 @@ 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 }); _diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId });
} }
} }
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, exception = ex }); _diagnostics.Write("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException", new { name = _middlewareName, httpContext = httpContext, instanceId = _instanceId, exception = ex });
} }
throw; throw;
} }