@@ -62,6 +62,7 @@ public class ScriptHost : JobHost
6262 private FileWatcherEventSource _fileEventSource ;
6363 private IDisposable _fileEventsSubscription ;
6464 private ProxyClientExecutor _proxyClient ;
65+ private ILoggerFactory _loggerFactory ;
6566
6667 protected internal ScriptHost ( IScriptHostEnvironment environment ,
6768 IScriptEventManager eventManager ,
@@ -288,13 +289,17 @@ protected virtual void Initialize()
288289 if ( hostConfig . LoggerFactory == null )
289290 {
290291 hostConfig . LoggerFactory = new LoggerFactory ( ) ;
291- }
292292
293- {
294- Func < string , FunctionDescriptor > funcLookup = ( name ) => this . GetFunctionOrNull ( name ) ;
295- hostConfig . AddService ( funcLookup ) ;
293+ // If we've created the LoggerFactory, then we are responsible for
294+ // disposing. Store this locally for disposal later. We can't rely
295+ // on accessing this directly from ScriptConfig.HostConfig as the
296+ // ScriptConfig is re-used for every host.
297+ _loggerFactory = hostConfig . LoggerFactory ;
296298 }
297299
300+ Func < string , FunctionDescriptor > funcLookup = ( name ) => this . GetFunctionOrNull ( name ) ;
301+ hostConfig . AddService ( funcLookup ) ;
302+
298303 // Set up a host level TraceMonitor that will receive notification
299304 // of ALL errors that occur. This allows us to inspect/log errors.
300305 var traceMonitor = new TraceMonitor ( )
@@ -1709,6 +1714,8 @@ protected override void Dispose(bool disposing)
17091714 {
17101715 ( function . Invoker as IDisposable ) ? . Dispose ( ) ;
17111716 }
1717+
1718+ _loggerFactory ? . Dispose ( ) ;
17121719 }
17131720
17141721 // dispose base last to ensure that errors there don't
0 commit comments