private void TrackWorkflowInstanceUnhandledExceptionRecord(WorkflowInstanceRecord record) { WorkflowInstanceUnhandledExceptionRecord unhandled = record as WorkflowInstanceUnhandledExceptionRecord; if (unhandled.WorkflowDefinitionIdentity == null) { if (WfEtwTrackingEventSource.Instance.WorkflowInstanceUnhandledExceptionRecordIsEnabled()) { WfEtwTrackingEventSource.Instance.WorkflowInstanceUnhandledExceptionRecord(unhandled.InstanceId, unhandled.RecordNumber, unhandled.EventTime, unhandled.ActivityDefinitionId, unhandled.FaultSource.Name, unhandled.FaultSource.Id, unhandled.FaultSource.InstanceId, unhandled.FaultSource.TypeName, unhandled.UnhandledException == null ? string.Empty : unhandled.UnhandledException.ToString(), unhandled.HasAnnotations ? JsonConvert.SerializeObject(unhandled.Annotations, Formatting.Indented) : emptyItemsTag, this.TrackingProfile == null ? string.Empty : this.TrackingProfile.Name, this.ApplicationReference); } } else { if (WfEtwTrackingEventSource.Instance.WorkflowInstanceUnhandledExceptionRecordWithIdIsEnabled()) { WfEtwTrackingEventSource.Instance.WorkflowInstanceUnhandledExceptionRecordWithId(unhandled.InstanceId, unhandled.RecordNumber, unhandled.EventTime, unhandled.ActivityDefinitionId, unhandled.FaultSource.Name, unhandled.FaultSource.Id, unhandled.FaultSource.InstanceId, unhandled.FaultSource.TypeName, unhandled.UnhandledException == null ? string.Empty : unhandled.UnhandledException.ToString(), unhandled.HasAnnotations ? JsonConvert.SerializeObject(unhandled.Annotations, Formatting.Indented) : emptyItemsTag, this.TrackingProfile == null ? string.Empty : this.TrackingProfile.Name == null ? string.Empty : this.TrackingProfile.Name, unhandled.WorkflowDefinitionIdentity.ToString(), this.ApplicationReference); } } }
/// <summary> /// Retreive each type of tracking record and perform the corresponding fucntionality. /// </summary> /// <param name="record">Represents the tracking record.</param> /// <param name="timeout">Time out for the tracking to be completed.</param> protected override void Track(TrackingRecord record, TimeSpan timeout) { Tracer.WriteMessage(String.Format(CultureInfo.InvariantCulture, "{0} Emitted trackRecord: {1} Level: {2}, RecordNumber: {3}", participantName, record.GetType().FullName, record.Level, record.RecordNumber)); WorkflowInstanceRecord workflowInstanceRecord = record as WorkflowInstanceRecord; if (workflowInstanceRecord != null) { if (_structuredTracer.IsEnabled) { if (string.Equals(WorkflowInstanceStates.Persisted, workflowInstanceRecord.State, StringComparison.OrdinalIgnoreCase)) { _structuredTracer.WorkflowPersisted(workflowInstanceRecord.InstanceId); } else if (string.Equals(WorkflowInstanceStates.UnhandledException, workflowInstanceRecord.State, StringComparison.OrdinalIgnoreCase)) { WorkflowInstanceUnhandledExceptionRecord unhandledRecord = workflowInstanceRecord as WorkflowInstanceUnhandledExceptionRecord; if (unhandledRecord != null) { _structuredTracer.WorkflowActivityExecutionFailed(unhandledRecord.InstanceId, unhandledRecord.FaultSource != null ? unhandledRecord.FaultSource.Name : unhandledRecord.ActivityDefinitionId, System.Management.Automation.Tracing.Tracer.GetExceptionString(unhandledRecord.UnhandledException)); } } } this.ProcessWorkflowInstanceRecord(workflowInstanceRecord); } ActivityStateRecord activityStateRecord = record as ActivityStateRecord; if (activityStateRecord != null) { if (_structuredTracer.IsEnabled) { ActivityInstanceState activityState = ActivityInstanceState.Executing; if (!string.IsNullOrEmpty(activityStateRecord.State) && Enum.TryParse <ActivityInstanceState>(activityStateRecord.State, out activityState)) { if (activityState == ActivityInstanceState.Executing) { _structuredTracer.ActivityExecutionQueued(activityStateRecord.InstanceId, activityStateRecord.Activity.Name); } } } this.ProcessActivityStateRecord(activityStateRecord); } CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord; if ((customTrackingRecord != null) && (customTrackingRecord.Data.Count > 0)) { this.ProcessCustomTrackingRecord(customTrackingRecord); } }
public override void Track(TrackingRecord record, TimeSpan timeout) { Type recordType = record.GetType(); Writer.WriteLine("[" + record.RecordNumber + "] ({" + record.EventTime + "}) Instance: " + record.InstanceId); if (record.Annotations.Count > 0) { Writer.WriteLine("Annotations:"); foreach (string key in record.Annotations.Keys) { Writer.WriteLine("\t" + key + "\t" + record.Annotations[key]); } } if (recordType == typeof(WorkflowInstanceUnhandledExceptionRecord)) { WorkflowInstanceUnhandledExceptionRecord crecord = (WorkflowInstanceUnhandledExceptionRecord)record; RecordWriteLine(crecord, "-----------Exception"); RecordWriteLine(crecord, crecord.UnhandledException.ToString()); RecordWriteLine(crecord, "-----------End Exception"); } else if (recordType == typeof(WorkflowInstanceRecord)) { WorkflowInstanceRecord crecord = (WorkflowInstanceRecord)record; RecordWriteLine(crecord, "Workflow State: " + crecord.State); } else if (recordType == typeof(ActivityTrackingRecord)) { ActivityTrackingRecord crecord = (ActivityTrackingRecord)record; RecordWriteLine(crecord, "Activity, " + crecord.Name + ", entered state: " + crecord.State); if (crecord.Variables.Count > 0) { Writer.WriteLine("Variables:"); foreach (string key in crecord.Variables.Keys) { Writer.WriteLine("\t" + key + "\t" + crecord.Variables[key].ToString()); } } } }
protected override void Track(TrackingRecord record, TimeSpan timeout) { lock (this) { WorkflowInstanceUnhandledExceptionRecord unhandledExceptionRecord = record as WorkflowInstanceUnhandledExceptionRecord; if (unhandledExceptionRecord != null) { ProcessInstRecord(unhandledExceptionRecord); Console.WriteLine("Exception executing workflow " + unhandledExceptionRecord); return; } WorkflowInstanceRecord wfInstRecord = record as WorkflowInstanceRecord; if (wfInstRecord != null) { ProcessInstRecord(wfInstRecord); return; } ActivityStateRecord activityStateRecord = record as ActivityStateRecord; if (activityStateRecord != null) { ProcessActivityStateRecord(activityStateRecord); return; } FaultPropagationRecord faultPropagationRecord = record as FaultPropagationRecord; if (faultPropagationRecord != null) { ProcessFaultPropagationRecord(faultPropagationRecord); return; } CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord; if (customTrackingRecord != null) { ProcessCustomTrackingRecord(customTrackingRecord); return; } } }
protected override void Track(TrackingRecord record, TimeSpan timeout) { WorkflowRecord message = new WorkflowRecord(); message.WFId = WFIdentifier; message.JobId = JobId; message.EventId = (int)record.RecordNumber; message.EventTime = record.EventTime.ToLocalTime(); message.RunId = record.InstanceId; WorkflowInstanceRecord wfRecord = record as WorkflowInstanceRecord; if (wfRecord != null) { message.State = wfRecord.State; message.Name = WorkflowName; if (wfRecord.State == WorkflowInstanceStates.Idle) { return; //do not track idle status } } ActivityStateRecord actRecord = record as ActivityStateRecord; if (actRecord != null) { message.State = actRecord.State; message.Name = actRecord.Activity.Name; if (actRecord.Activity.Name.Equals("DynamicActivity")) { return; } if (actRecord.State == ActivityStates.Executing && actRecord.Activity.TypeName == "System.Activities.Statements.WriteLine") { using (StringWriter writer = new StringWriter()) { writer.Write(actRecord.Arguments["Text"]); message.Message = writer.ToString(); writer.Close(); } } } WorkflowInstanceUnhandledExceptionRecord exRecord = record as WorkflowInstanceUnhandledExceptionRecord; if (exRecord != null) { message.State = exRecord.State; message.Name = WorkflowName; message.Message = exRecord.UnhandledException.Message; } CustomTrackingRecord cuRecord = record as CustomTrackingRecord; if (cuRecord != null) { message.Name = cuRecord.Activity.Name; message.State = cuRecord.Name; message.Message = cuRecord.Data["Message"] as string; } logWorkflowEvents.InsertEvent(message); }
protected override void Track(TrackingRecord record, TimeSpan timeout) { string name; object[] fullName = new object[4]; fullName[0] = "WorkflowTrackingParticipant"; fullName[1] = record.GetType().FullName; fullName[2] = record.Level; fullName[3] = record.RecordNumber; this.Tracer.WriteMessage(string.Format(CultureInfo.InvariantCulture, "{0} Emitted trackRecord: {1} Level: {2}, RecordNumber: {3}", fullName)); WorkflowInstanceRecord workflowInstanceRecord = record as WorkflowInstanceRecord; if (workflowInstanceRecord != null) { if (this._structuredTracer.IsEnabled) { if (!string.Equals("Persisted", workflowInstanceRecord.State, StringComparison.OrdinalIgnoreCase)) { if (string.Equals("UnhandledException", workflowInstanceRecord.State, StringComparison.OrdinalIgnoreCase)) { WorkflowInstanceUnhandledExceptionRecord workflowInstanceUnhandledExceptionRecord = workflowInstanceRecord as WorkflowInstanceUnhandledExceptionRecord; if (workflowInstanceUnhandledExceptionRecord != null) { Tracer tracer = this._structuredTracer; Guid instanceId = workflowInstanceUnhandledExceptionRecord.InstanceId; if (workflowInstanceUnhandledExceptionRecord.FaultSource != null) { name = workflowInstanceUnhandledExceptionRecord.FaultSource.Name; } else { name = workflowInstanceUnhandledExceptionRecord.ActivityDefinitionId; } tracer.WorkflowActivityExecutionFailed(instanceId, name, Tracer.GetExceptionString(workflowInstanceUnhandledExceptionRecord.UnhandledException)); } } } else { this._structuredTracer.WorkflowPersisted(workflowInstanceRecord.InstanceId); } } this.ProcessWorkflowInstanceRecord(workflowInstanceRecord); } ActivityStateRecord activityStateRecord = record as ActivityStateRecord; if (activityStateRecord != null) { if (this._structuredTracer.IsEnabled) { ActivityInstanceState activityInstanceState = ActivityInstanceState.Executing; if (!string.IsNullOrEmpty(activityStateRecord.State) && Enum.TryParse <ActivityInstanceState>(activityStateRecord.State, out activityInstanceState) && activityInstanceState == ActivityInstanceState.Executing) { this._structuredTracer.ActivityExecutionQueued(activityStateRecord.InstanceId, activityStateRecord.Activity.Name); } } this.ProcessActivityStateRecord(activityStateRecord); } CustomTrackingRecord customTrackingRecord = record as CustomTrackingRecord; if (customTrackingRecord != null && customTrackingRecord.Data.Count > 0) { this.ProcessCustomTrackingRecord(customTrackingRecord); } }