diff --git a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs index 9f7a88551..3eebe047c 100644 --- a/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs +++ b/src/PowerShellEditorServices.Hosting/Commands/StartEditorServicesCommand.cs @@ -298,14 +298,14 @@ private void StartLogging() private string GetLogDirPath() { - if (!string.IsNullOrEmpty(LogPath)) - { - return Path.GetDirectoryName(LogPath); - } + string logDir = !string.IsNullOrEmpty(LogPath) + ? Path.GetDirectoryName(LogPath) + : Path.GetDirectoryName(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); + + // Ensure logDir exists + Directory.CreateDirectory(logDir); - return Path.GetDirectoryName( - Path.GetDirectoryName( - Assembly.GetExecutingAssembly().Location)); + return logDir; } private void RemovePSReadLineForStartup()