From 1b01da7a05ccaf4a2b131c19d5ee3d163c1d7d7e Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 8 Feb 2017 18:48:19 +0000 Subject: [PATCH] Check hostingLog enabled (#933) --- .../Internal/HostingApplication.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs b/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs index af2a607b1f..5f95916e89 100644 --- a/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs +++ b/src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs @@ -43,7 +43,11 @@ namespace Microsoft.AspNetCore.Hosting.Internal _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 { @@ -56,7 +60,7 @@ namespace Microsoft.AspNetCore.Hosting.Internal public void DisposeContext(Context context, Exception exception) { var httpContext = context.HttpContext; - + var hostingLog = HostingEventSource.Log; if (exception == null) { 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 }); } - HostingEventSource.Log.UnhandledException(); + if (hostingLog.IsEnabled()) + { + hostingLog.UnhandledException(); + } } - HostingEventSource.Log.RequestStop(); + if (hostingLog.IsEnabled()) + { + hostingLog.RequestStop(); + } context.Scope?.Dispose();