Skip to content

Commit 1def7c2

Browse files
committed
Logging host configuration on initialization
1 parent bd63b0b commit 1def7c2

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed

src/WebJobs.Script/Host/ScriptHost.cs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -279,28 +279,6 @@ protected virtual void Initialize()
279279
hostConfig.LoggerFactory = new LoggerFactory();
280280
}
281281

282-
string json = File.ReadAllText(hostConfigFilePath);
283-
JObject hostConfigObject;
284-
try
285-
{
286-
hostConfigObject = JObject.Parse(json);
287-
}
288-
catch (JsonException ex)
289-
{
290-
throw new FormatException(string.Format("Unable to parse {0} file.", ScriptConstants.HostMetadataFileName), ex);
291-
}
292-
293-
ApplyConfiguration(hostConfigObject, ScriptConfig);
294-
295-
if (string.IsNullOrEmpty(hostConfig.HostId))
296-
{
297-
hostConfig.HostId = Utility.GetDefaultHostId(_settingsManager, ScriptConfig);
298-
}
299-
if (string.IsNullOrEmpty(hostConfig.HostId))
300-
{
301-
throw new InvalidOperationException("An 'id' must be specified in the host configuration.");
302-
}
303-
304282
// Set up a host level TraceMonitor that will receive notification
305283
// of ALL errors that occur. This allows us to inspect/log errors.
306284
var traceMonitor = new TraceMonitor()
@@ -343,6 +321,37 @@ protected virtual void Initialize()
343321
_startupLogger = hostConfig.LoggerFactory.CreateLogger(LogCategories.Startup);
344322
Logger = hostConfig.LoggerFactory.CreateLogger(ScriptConstants.LogCategoryHostGeneral);
345323

324+
string message = string.Format(CultureInfo.InvariantCulture, "Reading host configuration file '{0}'", hostConfigFilePath);
325+
TraceWriter.Info(message);
326+
_startupLogger?.LogInformation(message);
327+
328+
string json = File.ReadAllText(hostConfigFilePath);
329+
330+
message = $"Host configuration file read:{Environment.NewLine}{json}";
331+
TraceWriter.Info(message);
332+
_startupLogger.LogInformation(message);
333+
334+
JObject hostConfigObject;
335+
try
336+
{
337+
hostConfigObject = JObject.Parse(json);
338+
}
339+
catch (JsonException ex)
340+
{
341+
throw new FormatException(string.Format("Unable to parse {0} file.", ScriptConstants.HostMetadataFileName), ex);
342+
}
343+
344+
ApplyConfiguration(hostConfigObject, ScriptConfig);
345+
346+
if (string.IsNullOrEmpty(hostConfig.HostId))
347+
{
348+
hostConfig.HostId = Utility.GetDefaultHostId(_settingsManager, ScriptConfig);
349+
}
350+
if (string.IsNullOrEmpty(hostConfig.HostId))
351+
{
352+
throw new InvalidOperationException("An 'id' must be specified in the host configuration.");
353+
}
354+
346355
_debugModeFileWatcher = new AutoRecoveringFileSystemWatcher(hostLogPath, ScriptConstants.DebugSentinelFileName,
347356
includeSubdirectories: false, changeTypes: WatcherChangeTypes.Created | WatcherChangeTypes.Changed);
348357

@@ -364,10 +373,6 @@ protected virtual void Initialize()
364373
var bindingProviders = LoadBindingProviders(ScriptConfig, hostConfigObject, TraceWriter, _startupLogger);
365374
ScriptConfig.BindingProviders = bindingProviders;
366375

367-
string message = string.Format(CultureInfo.InvariantCulture, "Reading host configuration file '{0}'", hostConfigFilePath);
368-
TraceWriter.Info(message);
369-
_startupLogger?.LogInformation(message);
370-
371376
if (ScriptConfig.FileWatchingEnabled)
372377
{
373378
_fileEventSource = new FileWatcherEventSource(EventManager, EventSources.ScriptFiles, ScriptConfig.RootScriptPath);

test/WebJobs.Script.Tests.Integration/Host/WebScriptHostManagerTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ public Fixture()
293293
string[] expectedPatterns = new string[]
294294
{
295295
"Info Reading host configuration file",
296+
"Info Host configuration file read",
296297
"Info Host lock lease acquired by instance ID '(.+)'",
297298
"Info Function 'Excluded' is marked as excluded",
298299
@"Info Generating ([0-9]+) job function\(s\)",

0 commit comments

Comments
 (0)