//private static List<string> m_TraceSourceInitialized = new List<string>(); private void initializeLog(TaskContext context, TaskInput inputArg) { if (m_Log == null) { string logTraceSourceName = null; ILogManager parentLogMgr = new LogManager(inputArg.LoggerFactory, "not-used"); LoggingContext parentLoggingContext = null; if (inputArg.Context.ContainsKey("ParentLoggingContext")) { parentLoggingContext = inputArg.Context["ParentLoggingContext"] as LoggingContext; if (parentLoggingContext?.LoggingScopes != null) { foreach (var scope in parentLoggingContext.LoggingScopes) { // If Log Trace Source name is in parent context it will be used. if (scope.Key == "LogTraceSourceName") { logTraceSourceName = scope.Value; } parentLogMgr.AddScope(scope.Key, scope.Value); } // Copy the previous SequenceId to ParentSequenceId to keep the track. if (parentLogMgr.CurrentScope.ContainsKey("SequenceId")) { parentLogMgr.AddScope("ParentSequenceId", parentLogMgr.CurrentScope["SequenceId"]); } else { parentLogMgr.AddScope("ParentSequenceId", null); } } } if (parentLoggingContext == null) { parentLoggingContext = new LoggingContext(); } // // If log trace source name is specified in the configuration it will be used even if the context contains a parent logtrace source name. var cfg = this.GetConfiguration(inputArg.Orchestration); if (cfg != null) { logTraceSourceName = cfg.LogTraceSourceName; } if (String.IsNullOrEmpty(logTraceSourceName)) { logTraceSourceName = this.GetType().FullName; } m_Log = new LogManager(inputArg.LoggerFactory, logTraceSourceName, parentLogMgr); // With new instance of the LogManager we always create a new SequenceId. m_Log.AddScope("SequenceId", Guid.NewGuid().ToString()); // Add an new ActivityId if not existing yet. if (!m_Log.CurrentScope.ContainsKey("ActivityId")) { m_Log.AddScope("ActivityId", Guid.NewGuid().ToString()); } // Add OrchestrationInstanceId if (!m_Log.CurrentScope.ContainsKey("OrchestrationInstanceId")) { m_Log.AddScope("OrchestrationInstanceId", context.OrchestrationInstance.InstanceId); } } }