@@ -35,6 +35,7 @@ export class Logger implements ILogger {
35
35
private logChannel : vscode . OutputChannel ;
36
36
private logFilePath : vscode . Uri ;
37
37
private logDirectoryCreated = false ;
38
+ private writingLog = false ;
38
39
39
40
constructor ( logLevelName : string , globalStorageUri : vscode . Uri ) {
40
41
this . logLevel = Logger . logLevelNameToValue ( logLevelName ) ;
@@ -194,11 +195,16 @@ export class Logger implements ILogger {
194
195
const timestampedMessage = Logger . timestampMessage ( message , level ) ;
195
196
this . logChannel . appendLine ( timestampedMessage ) ;
196
197
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
+ }
197
202
try {
203
+ this . writingLog = true ;
198
204
if ( ! this . logDirectoryCreated ) {
199
205
this . logChannel . appendLine ( Logger . timestampMessage ( `Creating log directory at: '${ this . logDirectoryPath } '` , level ) ) ;
200
206
await vscode . workspace . fs . createDirectory ( this . logDirectoryPath ) ;
201
- this . logDirectoryCreated = await utils . checkIfDirectoryExists ( this . logDirectoryPath ) ;
207
+ this . logDirectoryCreated = true ;
202
208
}
203
209
let log = new Uint8Array ( ) ;
204
210
if ( await utils . checkIfFileExists ( this . logFilePath ) ) {
@@ -209,6 +215,8 @@ export class Logger implements ILogger {
209
215
Buffer . concat ( [ log , Buffer . from ( timestampedMessage ) ] ) ) ;
210
216
} catch ( e ) {
211
217
console . log ( `Error writing to vscode-powershell log file: ${ e } ` ) ;
218
+ } finally {
219
+ this . writingLog = false ;
212
220
}
213
221
}
214
222
}
0 commit comments