@@ -35,6 +35,7 @@ export class Logger implements ILogger {
3535 private logChannel : vscode . OutputChannel ;
3636 private logFilePath : vscode . Uri ;
3737 private logDirectoryCreated = false ;
38+ private writingLog = false ;
3839
3940 constructor ( logLevelName : string , globalStorageUri : vscode . Uri ) {
4041 this . logLevel = Logger . logLevelNameToValue ( logLevelName ) ;
@@ -194,11 +195,16 @@ export class Logger implements ILogger {
194195 const timestampedMessage = Logger . timestampMessage ( message , level ) ;
195196 this . logChannel . appendLine ( timestampedMessage ) ;
196197 if ( this . logLevel !== LogLevel . None ) {
198+ // A simple lock because this function isn't re-entrant.
199+ while ( this . writingLog ) {
200+ await utils . sleep ( 300 ) ;
201+ }
197202 try {
203+ this . writingLog = true ;
198204 if ( ! this . logDirectoryCreated ) {
199205 this . logChannel . appendLine ( Logger . timestampMessage ( `Creating log directory at: '${ this . logDirectoryPath } '` , level ) ) ;
200206 await vscode . workspace . fs . createDirectory ( this . logDirectoryPath ) ;
201- this . logDirectoryCreated = await utils . checkIfDirectoryExists ( this . logDirectoryPath ) ;
207+ this . logDirectoryCreated = true ;
202208 }
203209 let log = new Uint8Array ( ) ;
204210 if ( await utils . checkIfFileExists ( this . logFilePath ) ) {
@@ -209,6 +215,8 @@ export class Logger implements ILogger {
209215 Buffer . concat ( [ log , Buffer . from ( timestampedMessage ) ] ) ) ;
210216 } catch ( e ) {
211217 console . log ( `Error writing to vscode-powershell log file: ${ e } ` ) ;
218+ } finally {
219+ this . writingLog = false ;
212220 }
213221 }
214222 }
0 commit comments