//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); // */ // } //} #endregion protected override TOutput Execute(TaskContext context, TInput taskInputArgs) { TOutput result = null; string activityId = ServiceHost.GetActivityIdFromContext(taskInputArgs.Context); Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("ActId", activityId); dict.Add("InstId", context.OrchestrationInstance.InstanceId); dict.Add("ExecId", context.OrchestrationInstance.ExecutionId); var logger = ServiceHost.GetLogger(this.GetType(), dict); try { logger?.LogDebug(EventIds.TaskBase.TaskStarted, "TaskBase: '{Task}' started successfully", this.GetType().FullName); result = RunTask(context, taskInputArgs, logger); logger?.LogDebug(EventIds.TaskBase.TaskEnded, "TaskBase: '{Task}' exited successfully", this.GetType().FullName); } catch (ValidationRuleException validationException) { var currentType = this.GetType(); string taskType = currentType.Namespace + "." + currentType.Name; var validatedData = Newtonsoft.Json.JsonConvert.SerializeObject(validationException.ValidatingInstance); string validationRulesResult = String.Empty; foreach (var res in validationException.ValidationResult.Results) { validationRulesResult += Environment.NewLine + "Rule " + res.Key + "=" + res.Value.ToString(); } LogManager.TraceErrValidationRule(validationException, taskType, validatedData, validationRulesResult); throw; } catch (Exception ex) { logger?.LogError(EventIds.TaskBase.TaskFailed, ex, "Task failed."); throw; } finally { } return(result); }
/// <summary> /// Invoked when orchestration has to be started. /// </summary> /// <param name="context"></param> /// <param name="orchestrationInput"></param> /// <returns></returns> public override async Task <TOutput> RunTask(OrchestrationContext context, TInput orchestrationInput) { TOutput result = null; string activityId = ServiceHost.GetActivityIdFromContext(orchestrationInput.Context); Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("ActId", activityId); dict.Add("InstId", context.OrchestrationInstance.InstanceId); dict.Add("ExecId", context.OrchestrationInstance.ExecutionId); var logger = ServiceHost.GetLogger(this.GetType(), dict); try { if (context.IsReplaying == false) { logger?.LogDebug(EventIds.OrchestrationBase.OrchestrationStarted, "OrchestrationBase: '{orchestration}' entered.", this.GetType().FullName); } m_OrchestrationConext = context; m_OrchestrationInput = orchestrationInput; result = await RunOrchestration(context, orchestrationInput, logger); if (context.IsReplaying == false) { logger?.LogDebug(EventIds.OrchestrationBase.OrchestrationEnded, "OrchestrationBase: '{orchestration}' exited successfully", this.GetType().FullName); } } catch (Exception ex) { logger?.LogError(EventIds.OrchestrationBase.OrchestrationFailed, ex, "Orchestration failed."); throw; } return(result); }