From 0176c446e76552dfe5e4280717c6ed9028178573 Mon Sep 17 00:00:00 2001 From: Rolf Kristensen Date: Sat, 19 Nov 2022 16:52:33 +0100 Subject: [PATCH] Changed AspNetAppBasePathLayoutRenderer to prioritize current directory (code layout) (#888) --- .../AspNetAppBasePathLayoutRenderer.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Shared/LayoutRenderers/AspNetAppBasePathLayoutRenderer.cs b/src/Shared/LayoutRenderers/AspNetAppBasePathLayoutRenderer.cs index c051b1bd..9a8a5227 100644 --- a/src/Shared/LayoutRenderers/AspNetAppBasePathLayoutRenderer.cs +++ b/src/Shared/LayoutRenderers/AspNetAppBasePathLayoutRenderer.cs @@ -48,7 +48,7 @@ internal IHostEnvironment HostEnvironment protected override void Append(StringBuilder builder, LogEventInfo logEvent) { var contentRootPath = _contentRootPath ?? (_contentRootPath = ResolveContentRootPath()); - builder.Append(contentRootPath ?? _currentAppPath); + builder.Append(contentRootPath ?? ResolveCurrentAppDirectory()); } private IHostEnvironment ResolveHostEnvironment() @@ -81,6 +81,9 @@ private static string TrimEndDirectorySeparator(string directoryPath) private static string ResolveCurrentAppDirectory() { + if (!string.IsNullOrEmpty(_currentAppPath)) + return _currentAppPath; + #if ASP_NET_CORE var currentAppPath = AppContext.BaseDirectory; #else @@ -96,23 +99,20 @@ private static string ResolveCurrentAppDirectory() { currentBasePath = currentAppPath; // Avoid using Windows-System32 as current directory } - return currentBasePath; + return _currentAppPath = TrimEndDirectorySeparator(currentBasePath); } catch { // Not supported or access denied - return currentAppPath; + return _currentAppPath = TrimEndDirectorySeparator(currentAppPath); } } /// protected override void InitializeLayoutRenderer() { - if (string.IsNullOrEmpty(_currentAppPath)) - { - // Capture current directory at startup, before it changes - _currentAppPath = TrimEndDirectorySeparator(ResolveCurrentAppDirectory()); - } + ResolveCurrentAppDirectory(); // Capture current directory at startup, before it changes + base.InitializeLayoutRenderer(); } ///