public static bool ReadFieldsFromEventRecord( EventRecord eventRecord, EventDefinition eventDefinition, TraceAggregationConfig traceAggregationConfig, out List <KeyValuePair <string, double> > numericalFields, out List <KeyValuePair <string, string> > stringFields, out string diffFieldValueString, string logSourceId) { numericalFields = new List <KeyValuePair <string, double> >(); stringFields = new List <KeyValuePair <string, string> >(); diffFieldValueString = string.Empty; // Figure out how many fields the event has int fieldCount = eventDefinition.Fields.Count; if (0 == fieldCount) { Utility.TraceSource.WriteError( logSourceId, "No fields found in event of type {0}.{1}.", eventDefinition.TaskName, eventDefinition.EventName); return(false); } // Get the field names and values try { ApplicationDataReader reader = new ApplicationDataReader( eventRecord.UserData, eventRecord.UserDataLength); foreach (FieldDefinition fieldDef in eventDefinition.Fields) { var fieldValue = TelemetryUtility.GetEtwEventRecordValue(reader, fieldDef, logSourceId); if (traceAggregationConfig.FieldsAndAggregationConfigs.ContainsKey(fieldDef.Name)) { if (null != fieldValue) { if (fieldValue is string) { stringFields.Add(new KeyValuePair <string, string>(fieldDef.Name, (string)fieldValue)); } else { if (fieldValue is double) { numericalFields.Add(new KeyValuePair <string, double>(fieldDef.Name, (double)fieldValue)); } else { Utility.TraceSource.WriteError( logSourceId, "Unexpected field value type read. TaskName : {0}, EventName : {1}, FieldName : {2}, FieldType : {3}", eventDefinition.TaskName, eventDefinition.EventName, fieldDef.Name, fieldDef.Type.ToString()); } } } } // look if field is the differentiator field if (traceAggregationConfig.DifferentiatorFieldName == fieldDef.Name) { if (null != fieldValue) { diffFieldValueString = fieldValue.ToString(); } } } } catch (Exception e) { Utility.TraceSource.WriteError( logSourceId, "Failed to get all the fields of event of type {0}.{1}. Exception info: {2}.", eventDefinition.TaskName, eventDefinition.EventName, e); return(false); } return(true); }