@@ -42,16 +42,16 @@ import { WorkspacesMainService } from 'vs/platform/workspaces/electron-main/work
4242import { IWorkspacesMainService } from 'vs/platform/workspaces/common/workspaces' ;
4343import { localize } from 'vs/nls' ;
4444import { mnemonicButtonLabel } from 'vs/base/common/labels' ;
45- import { createLogService } from 'vs/platform/log/node/spdlogService' ;
45+ import { createSpdLogService } from 'vs/platform/log/node/spdlogService' ;
4646import { printDiagnostics } from 'vs/code/electron-main/diagnostics' ;
47+ import { BufferLogService } from 'vs/platform/log/common/bufferLog' ;
4748
48- function createServices ( args : ParsedArgs ) : IInstantiationService {
49+ function createServices ( args : ParsedArgs , bufferLogService : BufferLogService ) : IInstantiationService {
4950 const services = new ServiceCollection ( ) ;
5051
5152 const environmentService = new EnvironmentService ( args , process . execPath ) ;
52- const spdlogService = createLogService ( 'main' , environmentService ) ;
5353 const consoleLogService = new ConsoleLogMainService ( environmentService ) ;
54- const logService = new MultiplexLogService ( [ consoleLogService , spdlogService ] ) ;
54+ const logService = new MultiplexLogService ( [ consoleLogService , bufferLogService ] ) ;
5555
5656 process . once ( 'exit' , ( ) => logService . dispose ( ) ) ;
5757
@@ -284,7 +284,12 @@ function main() {
284284 return ;
285285 }
286286
287- const instantiationService = createServices ( args ) ;
287+ // We need to buffer the spdlog logs until we are sure
288+ // we are the only instance running, otherwise we'll have concurrent
289+ // log file access on Windows
290+ // https://github.com/Microsoft/vscode/issues/41218
291+ const bufferLogService = new BufferLogService ( ) ;
292+ const instantiationService = createServices ( args , bufferLogService ) ;
288293
289294 return instantiationService . invokeFunction ( accessor => {
290295
@@ -300,7 +305,10 @@ function main() {
300305 // Startup
301306 return instantiationService . invokeFunction ( a => createPaths ( a . get ( IEnvironmentService ) ) )
302307 . then ( ( ) => instantiationService . invokeFunction ( setupIPC ) )
303- . then ( mainIpcServer => instantiationService . createInstance ( CodeApplication , mainIpcServer , instanceEnv ) . startup ( ) ) ;
308+ . then ( mainIpcServer => {
309+ bufferLogService . logger = createSpdLogService ( 'main' , environmentService ) ;
310+ return instantiationService . createInstance ( CodeApplication , mainIpcServer , instanceEnv ) . startup ( ) ;
311+ } ) ;
304312 } ) . done ( null , err => instantiationService . invokeFunction ( quit , err ) ) ;
305313}
306314
0 commit comments