@@ -62,6 +62,7 @@ public class ScriptHost : JobHost
62
62
private FileWatcherEventSource _fileEventSource ;
63
63
private IDisposable _fileEventsSubscription ;
64
64
private ProxyClientExecutor _proxyClient ;
65
+ private ILoggerFactory _loggerFactory ;
65
66
66
67
protected internal ScriptHost ( IScriptHostEnvironment environment ,
67
68
IScriptEventManager eventManager ,
@@ -288,13 +289,17 @@ protected virtual void Initialize()
288
289
if ( hostConfig . LoggerFactory == null )
289
290
{
290
291
hostConfig . LoggerFactory = new LoggerFactory ( ) ;
291
- }
292
292
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 ;
296
298
}
297
299
300
+ Func < string , FunctionDescriptor > funcLookup = ( name ) => this . GetFunctionOrNull ( name ) ;
301
+ hostConfig . AddService ( funcLookup ) ;
302
+
298
303
// Set up a host level TraceMonitor that will receive notification
299
304
// of ALL errors that occur. This allows us to inspect/log errors.
300
305
var traceMonitor = new TraceMonitor ( )
@@ -1709,6 +1714,8 @@ protected override void Dispose(bool disposing)
1709
1714
{
1710
1715
( function . Invoker as IDisposable ) ? . Dispose ( ) ;
1711
1716
}
1717
+
1718
+ _loggerFactory ? . Dispose ( ) ;
1712
1719
}
1713
1720
1714
1721
// dispose base last to ensure that errors there don't
0 commit comments