@@ -35,12 +35,15 @@ 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 ) ;
4142 this . logChannel = vscode . window . createOutputChannel ( "PowerShell Extension Logs" ) ;
43+ // We have to override the scheme because it defaults to
44+ // 'vscode-userdata' which breaks UNC paths.
4245 this . logDirectoryPath = vscode . Uri . joinPath (
43- globalStorageUri ,
46+ globalStorageUri . with ( { scheme : "file" } ) ,
4447 "logs" ,
4548 `${ Math . floor ( Date . now ( ) / 1000 ) } -${ vscode . env . sessionId } ` ) ;
4649 this . logFilePath = this . getLogFilePath ( "vscode-powershell" ) ;
@@ -194,11 +197,16 @@ export class Logger implements ILogger {
194197 const timestampedMessage = Logger . timestampMessage ( message , level ) ;
195198 this . logChannel . appendLine ( timestampedMessage ) ;
196199 if ( this . logLevel !== LogLevel . None ) {
200+ // A simple lock because this function isn't re-entrant.
201+ while ( this . writingLog ) {
202+ await utils . sleep ( 300 ) ;
203+ }
197204 try {
205+ this . writingLog = true ;
198206 if ( ! this . logDirectoryCreated ) {
199207 this . logChannel . appendLine ( Logger . timestampMessage ( `Creating log directory at: '${ this . logDirectoryPath } '` , level ) ) ;
200208 await vscode . workspace . fs . createDirectory ( this . logDirectoryPath ) ;
201- this . logDirectoryCreated = await utils . checkIfDirectoryExists ( this . logDirectoryPath ) ;
209+ this . logDirectoryCreated = true ;
202210 }
203211 let log = new Uint8Array ( ) ;
204212 if ( await utils . checkIfFileExists ( this . logFilePath ) ) {
@@ -209,6 +217,8 @@ export class Logger implements ILogger {
209217 Buffer . concat ( [ log , Buffer . from ( timestampedMessage ) ] ) ) ;
210218 } catch ( e ) {
211219 console . log ( `Error writing to vscode-powershell log file: ${ e } ` ) ;
220+ } finally {
221+ this . writingLog = false ;
212222 }
213223 }
214224 }
0 commit comments