Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/WebJobs.Script/Host/ScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class ScriptHost : JobHost
private FileWatcherEventSource _fileEventSource;
private IDisposable _fileEventsSubscription;
private ProxyClientExecutor _proxyClient;
private ILoggerFactory _loggerFactory;

protected internal ScriptHost(IScriptHostEnvironment environment,
IScriptEventManager eventManager,
Expand Down Expand Up @@ -288,13 +289,17 @@ protected virtual void Initialize()
if (hostConfig.LoggerFactory == null)
{
hostConfig.LoggerFactory = new LoggerFactory();
}

{
Func<string, FunctionDescriptor> funcLookup = (name) => this.GetFunctionOrNull(name);
hostConfig.AddService(funcLookup);
// If we've created the LoggerFactory, then we are responsible for
// disposing. Store this locally for disposal later. We can't rely
// on accessing this directly from ScriptConfig.HostConfig as the
// ScriptConfig is re-used for every host.
_loggerFactory = hostConfig.LoggerFactory;
}

Func<string, FunctionDescriptor> funcLookup = (name) => this.GetFunctionOrNull(name);
hostConfig.AddService(funcLookup);

// Set up a host level TraceMonitor that will receive notification
// of ALL errors that occur. This allows us to inspect/log errors.
var traceMonitor = new TraceMonitor()
Expand Down Expand Up @@ -1709,6 +1714,8 @@ protected override void Dispose(bool disposing)
{
(function.Invoker as IDisposable)?.Dispose();
}

_loggerFactory?.Dispose();
}

// dispose base last to ensure that errors there don't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,20 @@ public async Task Validate_HostLogs()
{
// Validate the host startup traces. Order by message string as the requests may come in
// slightly out-of-order or on different threads
TraceTelemetry[] traces = _fixture.Channel.Telemetries
.OfType<TraceTelemetry>()
.Where(t => t.Context.Operation.Id == null)
.OrderBy(t => t.Message)
.ToArray();
TraceTelemetry[] traces = null;

await TestHelpers.Await(() =>
{
traces = _fixture.Channel.Telemetries
.OfType<TraceTelemetry>()
.Where(t => t.Context.Operation.Id == null)
.OrderBy(t => t.Message)
.ToArray();

return traces.Length >= 10;
});

Assert.Equal(10, traces.Length);
Assert.True(traces.Length == 10, $"Expected 10 messages, but found {traces.Length}. Actual logs:{Environment.NewLine}{string.Join(Environment.NewLine, traces.Select(t => t.Message))}");

ValidateTrace(traces[0], "Found the following functions:\r\n", LogCategories.Startup);
ValidateTrace(traces[1], "Generating 2 job function(s)", LogCategories.Startup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"name": "input",
"direction": "in",
"databaseName": "ItemDb",
"collectionName": "ItemCollection"
"collectionName": "ItemCollection",
"createLeaseCollectionIfNotExists": true
},
{
"type": "blob",
Expand Down