internal static string FormatStringEvent(int formatVersion, EventRecord eventRecord, out string eventType, out string eventText) { ApplicationDataReader reader = new ApplicationDataReader(eventRecord.UserData, eventRecord.UserDataLength); string text = reader.ReadUnicodeString(); string levelString; switch (eventRecord.EventHeader.EventDescriptor.Level) { case 2: levelString = "Error"; break; case 3: levelString = "Warning"; break; case 4: levelString = "Informational"; break; case 5: levelString = "Verbose"; break; default: levelString = "Unknown"; break; } eventText = text; string taskName; switch (formatVersion) { case 0: { eventType = eventRecord.EventHeader.ProviderId.ToString(string.Empty); taskName = StringEventTaskName; } break; default: { eventType = String.Empty; taskName = String.Empty; } break; } return(EventFormatter.FormatEvent((EventFormatter.FormatVersion)formatVersion, CultureInfo.InvariantCulture, eventRecord, null, levelString, taskName, String.Empty, String.Empty, eventType, text)); }
internal string FormatEvent(EventStack stack, EventRecord eventRecord, ValueMaps valueMaps, out string eventType, out string eventText, int formatVersion) { try { // This inefficient code is only a placeholder // once we make it work on all primitive types this will be // pre-compiled Linq Expression EventRecord->String ApplicationDataReader reader = new ApplicationDataReader(eventRecord.UserData, eventRecord.UserDataLength); eventType = this.eventName; string type = this.originalEventName; string id = string.Empty; string[] values = new string[fields.Count]; for (int i = 0; i < this.fields.Count; i++) { FieldDefinition fieldDef = this.fields[i]; values[i] = fieldDef.FormatField(CultureInfo.InvariantCulture, reader, valueMaps); } if (this.isParentEvent) { for (int i = this.fields.Count - 1; i >= 0; i--) { if (this.fields[i].IsContextField) { values[i] = stack.Pop(eventRecord.EventHeader.ProcessId, eventRecord.EventHeader.ThreadId, values[i], this.firstContextFieldIndex == i); if (values[i] == null) { values[i] = " !!!Context Data Not Found!!! "; } } } } if (this.typeFieldIndex != -1) { type = eventType = values[typeFieldIndex]; } eventText = FormatWithFieldValues(values, out id); if (id.Length > 0) { type += "@" + id; } if (this.isChildEvent) { stack.Push(eventRecord.EventHeader.ProcessId, eventRecord.EventHeader.ThreadId, values[0], eventText); return(null); } return(EventFormatter.FormatEvent( string.IsNullOrEmpty(this.eventSourceName) ? (EventFormatter.FormatVersion)formatVersion : EventFormatter.FormatVersion.EventSourceBasedFormatting, CultureInfo.InvariantCulture, eventRecord, this.eventSourceName, this.level, this.taskName, this.opcodeName, this.keywordsName, type, eventText)); } catch (Exception e) { throw new InvalidDataException( string.Format(CultureInfo.InvariantCulture, "Unable to parse event {0}.{1} id {2} eventsource {3}", this.TaskName, this.EventName, this.id, this.eventSourceName), e); } }