From aeea62178f798478d5f7a18adb4f60d9410a9e6b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 5 Mar 2020 13:34:50 -0800 Subject: [PATCH 1/2] Ensure log directory is created --- .../Commands/StartEditorServicesCommand.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 9f7a88551..973b92c10 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -298,14 +298,17 @@ private void StartLogging() private string GetLogDirPath() { - if (!string.IsNullOrEmpty(LogPath)) + string logDir = !string.IsNullOrEmpty(LogPath) + ? Path.GetDirectoryName(LogPath) + : Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); + + // Ensure logDir exists + if (!Directory.Exists(logDir)) { - return Path.GetDirectoryName(LogPath); + Directory.CreateDirectory(logDir); } - return Path.GetDirectoryName( - Path.GetDirectoryName( - Assembly.GetExecutingAssembly().Location)); + return logDir; } private void RemovePSReadLineForStartup() From 4a0bbaf93b6ebbf7141c61ceb0dd521584bff4c9 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 5 Mar 2020 13:56:19 -0800 Subject: [PATCH 2/2] remove duplicate check --- .../Commands/StartEditorServicesCommand.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 973b92c10..3eebe047c 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -303,10 +303,7 @@ private string GetLogDirPath() : Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); // Ensure logDir exists - if (!Directory.Exists(logDir)) - { - Directory.CreateDirectory(logDir); - } + Directory.CreateDirectory(logDir); return logDir; }