From f967e29bff4ad4fa451dbaf450772476b9d5e0e0 Mon Sep 17 00:00:00 2001 From: Julian Verdurmen <304NotModified@users.noreply.github.com> Date: Mon, 1 May 2017 22:29:47 +0200 Subject: [PATCH] Improve performance with many threads --- .../LayoutRenderers/AspNetLayoutRendererBase.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/NLog.Web.AspNetCore/LayoutRenderers/AspNetLayoutRendererBase.cs b/NLog.Web.AspNetCore/LayoutRenderers/AspNetLayoutRendererBase.cs index 64a43a1c..cf923238 100644 --- a/NLog.Web.AspNetCore/LayoutRenderers/AspNetLayoutRendererBase.cs +++ b/NLog.Web.AspNetCore/LayoutRenderers/AspNetLayoutRendererBase.cs @@ -38,10 +38,21 @@ protected AspNetLayoutRendererBase() /// HttpContextAccessor or null public IHttpContextAccessor HttpContextAccessor { - get { return _httpContextAccessor ?? ServiceLocator.ServiceProvider?.GetService(); } + get { return _httpContextAccessor ?? (_httpContextAccessor = ServiceLocator.ServiceProvider?.GetService()); } set { _httpContextAccessor = value; } } + /// + /// Initialize + /// + protected override void InitializeLayoutRenderer() + { + if (HttpContextAccessor == null) + { + Common.InternalLogger.Warn("Missing IHttpContextAccessor. Has it been registered before loading NLog Configuration? Consider reloading NLog Configuration after having registered the IHttpContextAccessor."); + } + } + #else /// /// Provides access to the current request HttpContext.