Check hostingLog enabled (#933)

This commit is contained in:
Ben Adams 2017-02-08 18:48:19 +00:00 committed by Chris R
parent 056a251b8c
commit 1b01da7a05
1 changed files with 14 additions and 4 deletions

View File

@ -43,7 +43,11 @@ namespace Microsoft.AspNetCore.Hosting.Internal
_diagnosticSource.Write("Microsoft.AspNetCore.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp }); _diagnosticSource.Write("Microsoft.AspNetCore.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp });
} }
HostingEventSource.Log.RequestStart(httpContext.Request.Method, httpContext.Request.Path); var hostingLog = HostingEventSource.Log;
if (hostingLog.IsEnabled())
{
hostingLog.RequestStart(httpContext.Request.Method, httpContext.Request.Path);
}
return new Context return new Context
{ {
@ -56,7 +60,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal
public void DisposeContext(Context context, Exception exception) public void DisposeContext(Context context, Exception exception)
{ {
var httpContext = context.HttpContext; var httpContext = context.HttpContext;
var hostingLog = HostingEventSource.Log;
if (exception == null) if (exception == null)
{ {
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.EndRequest"); var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.EndRequest");
@ -81,10 +85,16 @@ namespace Microsoft.AspNetCore.Hosting.Internal
_diagnosticSource.Write("Microsoft.AspNetCore.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception }); _diagnosticSource.Write("Microsoft.AspNetCore.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception });
} }
HostingEventSource.Log.UnhandledException(); if (hostingLog.IsEnabled())
{
hostingLog.UnhandledException();
}
} }
HostingEventSource.Log.RequestStop(); if (hostingLog.IsEnabled())
{
hostingLog.RequestStop();
}
context.Scope?.Dispose(); context.Scope?.Dispose();