Exemple #1
0
        public string FormatEvent(EventRecord eventRecord, out string eventType, out string eventText, int formatVersion = 0)
        {
            eventType = null;
            eventText = null;
            string s = null;

            // Check if this is a special event from EventSource which contains manifest
            if (ProcessEventSourceEvent(eventRecord))
            {
                // Stop further processing for this event, we don't want it to be displayed as well so return null
                return(null);
            }

            if (ManifestCache.IsStringEvent(eventRecord))
            {
                s = EventFormatter.FormatStringEvent(formatVersion, eventRecord, out eventType, out eventText);
            }

            if (s == null)
            {
                ProviderDefinition providerDef;
                if (this.providers.TryGetValue(eventRecord.EventHeader.ProviderId, out providerDef))
                {
                    s = providerDef.FormatEvent(eventRecord, out eventType, out eventText, formatVersion);
                }
            }

            return(s);
        }
        internal static string FormatEvent(FormatVersion formatVersion, IFormatProvider provider, EventRecord eventRecord, string eventSourceName, string eventLevel, string eventTaskName, string opcodeName, string keywordsName, string type, string text)
        {
            switch (formatVersion)
            {
            case FormatVersion.TaskBasedFormatting:
            {
                return(string.Format(
                           provider,
                           "{0},{1},{2},{3},{4}.{5},{6}",
                           EventFormatter.FormatTimeStamp(provider, eventRecord.EventHeader.TimeStamp),
                           eventLevel,
                           eventRecord.EventHeader.ThreadId,
                           eventRecord.EventHeader.ProcessId,
                           eventTaskName,
                           type,
                           text));
            }

            case FormatVersion.EventSourceBasedFormatting:
            {
                return(string.Format(
                           provider,
                           "{0},{1},{2},{3},{4}.{5},{6}",
                           EventFormatter.FormatTimeStamp(provider, eventRecord.EventHeader.TimeStamp),
                           eventLevel,
                           eventRecord.EventHeader.ThreadId,
                           eventRecord.EventHeader.ProcessId,
                           eventSourceName,
                           type,
                           text));
            }

            default:
            {
                return(string.Format(
                           provider,
                           "{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}",
                           EventFormatter.FormatTimeStamp(provider, eventRecord.EventHeader.TimeStamp),
                           eventRecord.EventHeader.ThreadId,
                           eventRecord.EventHeader.ProcessId,
                           eventRecord.EventHeader.EventDescriptor.Id,
                           eventRecord.EventHeader.ActivityId,
                           GetRelatedActivityId(eventRecord),
                           eventLevel,
                           String.IsNullOrEmpty(eventTaskName) ?
                           eventRecord.EventHeader.EventDescriptor.Task.ToString(provider) :
                           eventTaskName,
                           String.IsNullOrEmpty(opcodeName) ?
                           eventRecord.EventHeader.EventDescriptor.Opcode.ToString(provider) :
                           opcodeName,
                           String.IsNullOrEmpty(keywordsName) ?
                           eventRecord.EventHeader.EventDescriptor.Keyword.ToString("X", provider) :
                           keywordsName,
                           type,
                           text));
            }
            }
        }
        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));
        }
        private static string FormatTimeStamp(IFormatProvider provider, long fileTime)
        {
            DateTime timestamp = DateTime.FromFileTimeUtc(fileTime);

            return(EventFormatter.FormatTimeStamp(provider, timestamp));
        }
        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);
            }
        }