internal FunctionInvokerBase(ScriptHost host, FunctionMetadata functionMetadata) { Host = host; Metadata = functionMetadata; _metrics = host.ScriptConfig.HostConfig.GetService <IMetricsLogger>(); // Function file logging is only done conditionally TraceWriter traceWriter = host.FunctionTraceWriterFactory.Create(functionMetadata.Name); FileTraceWriter = traceWriter.Conditional(t => Host.FileLoggingEnabled && (!(t.Properties?.ContainsKey(ScriptConstants.TracePropertyPrimaryHostKey) ?? false) || Host.IsPrimary)); // The global trace writer used by the invoker will write all traces to both // the host trace writer as well as our file trace writer TraceWriter = host.TraceWriter != null ? new CompositeTraceWriter(new TraceWriter[] { FileTraceWriter, host.TraceWriter }) : FileTraceWriter; // Apply the function name as an event property to all traces var functionTraceProperties = new Dictionary <string, object> { { ScriptConstants.TracePropertyFunctionNameKey, Metadata.Name } }; TraceWriter = TraceWriter.Apply(functionTraceProperties); Logger = host.ScriptConfig.HostConfig.LoggerFactory?.CreateLogger(LogCategories.Executor); }
public FunctionLogger(ScriptHost host, string functionName, string logDirName = null) { // Function file logging is only done conditionally TraceWriter traceWriter = host.FunctionTraceWriterFactory.Create(functionName, logDirName); FileTraceWriter = traceWriter.Conditional(t => host.FileLoggingEnabled && (!(t.Properties?.ContainsKey(ScriptConstants.TracePropertyPrimaryHostKey) ?? false) || host.IsPrimary)); // The global trace writer used by the invoker will write all traces to both // the host trace writer as well as our file trace writer traceWriter = host.TraceWriter != null ? new CompositeTraceWriter(new TraceWriter[] { FileTraceWriter, host.TraceWriter }) : FileTraceWriter; // Apply the function name as an event property to all traces var functionTraceProperties = new Dictionary <string, object> { { ScriptConstants.TracePropertyFunctionNameKey, functionName } }; TraceWriter = traceWriter.Apply(functionTraceProperties); Logger = host.ScriptConfig.HostConfig.LoggerFactory?.CreateLogger(LogCategories.Executor); }