static string BuildTrace(ref EventDescriptor eventDescriptor, string description, TracePayload payload) { StringBuilder sb = new StringBuilder(); XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb, CultureInfo.CurrentCulture)); writer.WriteStartElement(DiagnosticStrings.TraceRecordTag); writer.WriteAttributeString(DiagnosticStrings.NamespaceTag, DiagnosticTrace.TraceRecordVersion); writer.WriteAttributeString(DiagnosticStrings.SeverityTag, TraceLevelHelper.LookupSeverity((TraceEventLevel)eventDescriptor.Level, (TraceEventOpcode)eventDescriptor.Opcode)); writer.WriteAttributeString(DiagnosticStrings.ChannelTag, DiagnosticTrace.LookupChannel((TraceChannel)eventDescriptor.Channel)); writer.WriteElementString(DiagnosticStrings.TraceCodeTag, DiagnosticTrace.GenerateTraceCode(ref eventDescriptor)); writer.WriteElementString(DiagnosticStrings.DescriptionTag, description); writer.WriteElementString(DiagnosticStrings.AppDomain, payload.AppDomainFriendlyName); if (!string.IsNullOrEmpty(payload.EventSource)) { writer.WriteElementString(DiagnosticStrings.SourceTag, payload.EventSource); } if (!string.IsNullOrEmpty(payload.ExtendedData)) { writer.WriteRaw(payload.ExtendedData); } if (!string.IsNullOrEmpty(payload.SerializedException)) { writer.WriteRaw(payload.SerializedException); } writer.WriteEndElement(); return(sb.ToString()); }
private static string BuildTrace(ref System.Diagnostics.Eventing.EventDescriptor eventDescriptor, string description, TracePayload payload) { StringBuilder stringBuilder = new StringBuilder(); XmlTextWriter xmlTextWriter = new XmlTextWriter(new StringWriter(stringBuilder, CultureInfo.CurrentCulture)); xmlTextWriter.WriteStartElement("TraceRecord"); xmlTextWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"); xmlTextWriter.WriteAttributeString("Severity", TraceLevelHelper.LookupSeverity((TraceEventLevel)eventDescriptor.Level, (TraceEventOpcode)eventDescriptor.Opcode)); xmlTextWriter.WriteAttributeString("Channel", DiagnosticTrace.LookupChannel((TraceChannel)eventDescriptor.Channel)); xmlTextWriter.WriteElementString("TraceIdentifier", DiagnosticTrace.GenerateTraceCode(ref eventDescriptor)); xmlTextWriter.WriteElementString("Description", description); xmlTextWriter.WriteElementString("AppDomain", payload.AppDomainFriendlyName); if (!string.IsNullOrEmpty(payload.EventSource)) { xmlTextWriter.WriteElementString("Source", payload.EventSource); } if (!string.IsNullOrEmpty(payload.ExtendedData)) { xmlTextWriter.WriteRaw(payload.ExtendedData); } if (!string.IsNullOrEmpty(payload.SerializedException)) { xmlTextWriter.WriteRaw(payload.SerializedException); } xmlTextWriter.WriteEndElement(); return(stringBuilder.ToString()); }
private static string BuildTrace(ref EventDescriptor eventDescriptor, string description, TracePayload payload, string msdnTraceCode) { string str; StringBuilder stringBuilder = EtwDiagnosticTrace.StringBuilderPool.Take(); try { using (StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.CurrentCulture)) { using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter)) { xmlTextWriter.WriteStartElement("TraceRecord"); xmlTextWriter.WriteAttributeString("xmlns", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord"); xmlTextWriter.WriteAttributeString("Severity", TraceLevelHelper.LookupSeverity((TraceEventLevel)eventDescriptor.Level, (TraceEventOpcode)eventDescriptor.Opcode)); xmlTextWriter.WriteAttributeString("Channel", EtwDiagnosticTrace.LookupChannel((TraceChannel)eventDescriptor.Channel)); xmlTextWriter.WriteElementString("TraceIdentifier", msdnTraceCode); xmlTextWriter.WriteElementString("Description", description); xmlTextWriter.WriteElementString("AppDomain", payload.AppDomainFriendlyName); if (!string.IsNullOrEmpty(payload.EventSource)) { xmlTextWriter.WriteElementString("Source", payload.EventSource); } if (!string.IsNullOrEmpty(payload.ExtendedData)) { xmlTextWriter.WriteRaw(payload.ExtendedData); } if (!string.IsNullOrEmpty(payload.SerializedException)) { xmlTextWriter.WriteRaw(payload.SerializedException); } xmlTextWriter.WriteEndElement(); xmlTextWriter.Flush(); stringWriter.Flush(); str = stringBuilder.ToString(); } } } finally { EtwDiagnosticTrace.StringBuilderPool.Return(stringBuilder); } return(str); }