@@ -266,30 +266,38 @@ protected virtual void Initialize()
266
266
File . WriteAllText ( hostConfigFilePath , "{}" ) ;
267
267
}
268
268
269
- if ( ScriptConfig . HostConfig . IsDevelopment || InDebugMode )
269
+ var hostConfig = ScriptConfig . HostConfig ;
270
+ if ( hostConfig . IsDevelopment || InDebugMode )
270
271
{
271
272
// If we're in debug/development mode, use optimal debug settings
272
- ScriptConfig . HostConfig . UseDevelopmentSettings ( ) ;
273
+ hostConfig . UseDevelopmentSettings ( ) ;
274
+ }
275
+
276
+ // Ensure we always have an ILoggerFactory,
277
+ // regardless of whether AppInsights is registered or not
278
+ if ( hostConfig . LoggerFactory == null )
279
+ {
280
+ hostConfig . LoggerFactory = new LoggerFactory ( ) ;
273
281
}
274
282
275
283
string json = File . ReadAllText ( hostConfigFilePath ) ;
276
- JObject hostConfig ;
284
+ JObject hostConfigObject ;
277
285
try
278
286
{
279
- hostConfig = JObject . Parse ( json ) ;
287
+ hostConfigObject = JObject . Parse ( json ) ;
280
288
}
281
289
catch ( JsonException ex )
282
290
{
283
291
throw new FormatException ( string . Format ( "Unable to parse {0} file." , ScriptConstants . HostMetadataFileName ) , ex ) ;
284
292
}
285
293
286
- ApplyConfiguration ( hostConfig , ScriptConfig ) ;
294
+ ApplyConfiguration ( hostConfigObject , ScriptConfig ) ;
287
295
288
- if ( string . IsNullOrEmpty ( ScriptConfig . HostConfig . HostId ) )
296
+ if ( string . IsNullOrEmpty ( hostConfig . HostId ) )
289
297
{
290
- ScriptConfig . HostConfig . HostId = Utility . GetDefaultHostId ( _settingsManager , ScriptConfig ) ;
298
+ hostConfig . HostId = Utility . GetDefaultHostId ( _settingsManager , ScriptConfig ) ;
291
299
}
292
- if ( string . IsNullOrEmpty ( ScriptConfig . HostConfig . HostId ) )
300
+ if ( string . IsNullOrEmpty ( hostConfig . HostId ) )
293
301
{
294
302
throw new InvalidOperationException ( "An 'id' must be specified in the host configuration." ) ;
295
303
}
@@ -299,9 +307,9 @@ protected virtual void Initialize()
299
307
var traceMonitor = new TraceMonitor ( )
300
308
. Filter ( p => { return true ; } )
301
309
. Subscribe ( HandleHostError ) ;
302
- ScriptConfig . HostConfig . Tracing . Tracers . Add ( traceMonitor ) ;
310
+ hostConfig . Tracing . Tracers . Add ( traceMonitor ) ;
303
311
304
- TraceLevel hostTraceLevel = ScriptConfig . HostConfig . Tracing . ConsoleLevel ;
312
+ TraceLevel hostTraceLevel = hostConfig . Tracing . ConsoleLevel ;
305
313
if ( ScriptConfig . FileLoggingMode != FileLoggingMode . Never )
306
314
{
307
315
// Host file logging is only done conditionally
@@ -321,7 +329,7 @@ protected virtual void Initialize()
321
329
322
330
if ( TraceWriter != null )
323
331
{
324
- ScriptConfig . HostConfig . Tracing . Tracers . Add ( TraceWriter ) ;
332
+ hostConfig . Tracing . Tracers . Add ( TraceWriter ) ;
325
333
}
326
334
else
327
335
{
@@ -333,8 +341,8 @@ protected virtual void Initialize()
333
341
334
342
// Use the startupLogger in this class as it is concerned with startup. The public Logger is used
335
343
// for all other logging after startup.
336
- _startupLogger = ScriptConfig . HostConfig . LoggerFactory . CreateLogger ( LogCategories . Startup ) ;
337
- Logger = ScriptConfig . HostConfig . LoggerFactory . CreateLogger ( ScriptConstants . LogCategoryHostGeneral ) ;
344
+ _startupLogger = hostConfig . LoggerFactory . CreateLogger ( LogCategories . Startup ) ;
345
+ Logger = hostConfig . LoggerFactory . CreateLogger ( ScriptConstants . LogCategoryHostGeneral ) ;
338
346
339
347
_debugModeFileWatcher = new AutoRecoveringFileSystemWatcher ( hostLogPath , ScriptConstants . DebugSentinelFileName ,
340
348
includeSubdirectories : false , changeTypes : WatcherChangeTypes . Created | WatcherChangeTypes . Changed ) ;
@@ -346,15 +354,15 @@ protected virtual void Initialize()
346
354
if ( storageString == null )
347
355
{
348
356
// Disable core storage
349
- ScriptConfig . HostConfig . StorageConnectionString = null ;
357
+ hostConfig . StorageConnectionString = null ;
350
358
blobManagerCreation = Task . FromResult < BlobLeaseManager > ( null ) ;
351
359
}
352
360
else
353
361
{
354
- blobManagerCreation = BlobLeaseManager . CreateAsync ( storageString , TimeSpan . FromSeconds ( 15 ) , ScriptConfig . HostConfig . HostId , InstanceId , TraceWriter , ScriptConfig . HostConfig . LoggerFactory ) ;
362
+ blobManagerCreation = BlobLeaseManager . CreateAsync ( storageString , TimeSpan . FromSeconds ( 15 ) , hostConfig . HostId , InstanceId , TraceWriter , hostConfig . LoggerFactory ) ;
355
363
}
356
364
357
- var bindingProviders = LoadBindingProviders ( ScriptConfig , hostConfig , TraceWriter , _startupLogger ) ;
365
+ var bindingProviders = LoadBindingProviders ( ScriptConfig , hostConfigObject , TraceWriter , _startupLogger ) ;
358
366
ScriptConfig . BindingProviders = bindingProviders ;
359
367
360
368
string message = string . Format ( CultureInfo . InvariantCulture , "Reading host configuration file '{0}'" , hostConfigFilePath ) ;
@@ -428,7 +436,7 @@ protected virtual void Initialize()
428
436
List < Type > types = new List < Type > ( ) ;
429
437
types . Add ( type ) ;
430
438
431
- ScriptConfig . HostConfig . TypeLocator = new TypeLocator ( types ) ;
439
+ hostConfig . TypeLocator = new TypeLocator ( types ) ;
432
440
433
441
Functions = functions ;
434
442
@@ -518,12 +526,6 @@ private void LoadExtension(IExtensionConfigProvider instance, string locationHin
518
526
internal static void ConfigureLoggerFactory ( ScriptHostConfiguration scriptConfig ,
519
527
ScriptSettingsManager settingsManager , IMetricsLogger metrics , Func < bool > isFileLoggingEnabled )
520
528
{
521
- // We always want an ILoggerFactory, whether app insights is registered or not
522
- if ( scriptConfig . HostConfig . LoggerFactory == null )
523
- {
524
- scriptConfig . HostConfig . LoggerFactory = new LoggerFactory ( ) ;
525
- }
526
-
527
529
// Register a file logger that only logs user logs and only if file logging is enabled
528
530
scriptConfig . HostConfig . LoggerFactory . AddProvider ( new FileLoggerProvider ( scriptConfig ,
529
531
( category , level ) => ( category == LogCategories . Function ) && isFileLoggingEnabled ( ) ) ) ;
0 commit comments