示例#1
0
        public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
        {
            string eventSource         = null;
            string extendedData        = null;
            string serializedException = null;

            if (source != null)
            {
                eventSource = CreateSourceString(source);
            }
            if (traceRecord != null)
            {
                StringBuilder sb     = new StringBuilder();
                XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb, CultureInfo.CurrentCulture));
                writer.WriteStartElement("ExtendedData");
                traceRecord.WriteTo(writer);
                writer.WriteEndElement();
                extendedData = sb.ToString();
            }
            if (exception != null)
            {
                serializedException = ExceptionToTraceString(exception);
            }
            if (getServiceReference && (traceAnnotation != null))
            {
                return(new TracePayload(serializedException, eventSource, appDomainFriendlyName, extendedData, traceAnnotation()));
            }
            return(new TracePayload(serializedException, eventSource, appDomainFriendlyName, extendedData, string.Empty));
        }
        public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
        {
            string eventSource         = null;
            string extendedData        = null;
            string serializedException = null;

            if (source != null)
            {
                eventSource = CreateSourceString(source);
            }

            if (traceRecord != null)
            {
                StringBuilder sb = StringBuilderPool.Take();
                try
                {
                    using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                    {
                        using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                        {
                            writer.WriteStartElement(DiagnosticStrings.ExtendedDataTag);
                            traceRecord.WriteTo(writer);
                            writer.WriteEndElement();
                            writer.Flush();
                            stringWriter.Flush();

                            extendedData = sb.ToString();
                        }
                    }
                }
                finally
                {
                    StringBuilderPool.Return(sb);
                }
            }

            if (exception != null)
            {
                // We want to keep the ETW trace message to under 32k. So we keep the serialized exception to under 28k bytes.
                serializedException = ExceptionToTraceString(exception, MaxExceptionStringLength);
            }

            if (getServiceReference && (EtwDiagnosticTrace.traceAnnotation != null))
            {
                return(new TracePayload(serializedException, eventSource, DiagnosticTraceBase.AppDomainFriendlyName, extendedData, EtwDiagnosticTrace.traceAnnotation()));
            }

            return(new TracePayload(serializedException, eventSource, DiagnosticTraceBase.AppDomainFriendlyName, extendedData, string.Empty));
        }
示例#3
0
        public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
        {
            string str         = null;
            string str1        = null;
            string traceString = null;

            if (source != null)
            {
                str = DiagnosticTraceBase.CreateSourceString(source);
            }
            if (traceRecord != null)
            {
                StringBuilder stringBuilder = EtwDiagnosticTrace.StringBuilderPool.Take();
                try
                {
                    using (StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.CurrentCulture))
                    {
                        using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
                        {
                            xmlTextWriter.WriteStartElement("ExtendedData");
                            traceRecord.WriteTo(xmlTextWriter);
                            xmlTextWriter.WriteEndElement();
                            xmlTextWriter.Flush();
                            stringWriter.Flush();
                            str1 = stringBuilder.ToString();
                        }
                    }
                }
                finally
                {
                    EtwDiagnosticTrace.StringBuilderPool.Return(stringBuilder);
                }
            }
            if (exception != null)
            {
                traceString = EtwDiagnosticTrace.ExceptionToTraceString(exception, 0x7000);
            }
            if (!getServiceReference || EtwDiagnosticTrace.traceAnnotation == null)
            {
                return(new TracePayload(traceString, str, DiagnosticTraceBase.AppDomainFriendlyName, str1, string.Empty));
            }
            else
            {
                return(new TracePayload(traceString, str, DiagnosticTraceBase.AppDomainFriendlyName, str1, EtwDiagnosticTrace.traceAnnotation()));
            }
        }
        public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
        {
            string eventSource = null;
            string extendedData = null;
            string serializedException = null;

            if (source != null)
            {
                eventSource = CreateSourceString(source);
            }

            if (traceRecord != null)
            {
                StringBuilder sb = StringBuilderPool.Take();
                try
                {
                    using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                    {
                        using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                        {
                            writer.WriteStartElement(DiagnosticStrings.ExtendedDataTag);
                            traceRecord.WriteTo(writer);
                            writer.WriteEndElement();
                            writer.Flush();
                            stringWriter.Flush();

                            extendedData = sb.ToString();
                        }
                    }
                }
                finally
                {
                    StringBuilderPool.Return(sb);
                }
            }

            if (exception != null)
            {
                // We want to keep the ETW trace message to under 32k. So we keep the serialized exception to under 28k bytes.
                serializedException = ExceptionToTraceString(exception, MaxExceptionStringLength);
            }

            if (getServiceReference && (EtwDiagnosticTrace.traceAnnotation != null))
            {
                return new TracePayload(serializedException, eventSource, DiagnosticTraceBase.AppDomainFriendlyName, extendedData, EtwDiagnosticTrace.traceAnnotation());
            }

            return new TracePayload(serializedException, eventSource, DiagnosticTraceBase.AppDomainFriendlyName, extendedData, string.Empty);
        }
        void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description,
            TraceRecord trace, Exception exception, object source)
        {
            xml.WriteStartElement(DiagnosticStrings.TraceRecordTag);
            xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, LegacyDiagnosticTrace.TraceRecordVersion);
            xml.WriteAttributeString(DiagnosticStrings.SeverityTag, DiagnosticTraceBase.LookupSeverity(type));

            xml.WriteElementString(DiagnosticStrings.TraceCodeTag, msdnTraceCode);
            xml.WriteElementString(DiagnosticStrings.DescriptionTag, description);
            xml.WriteElementString(DiagnosticStrings.AppDomain, DiagnosticTraceBase.AppDomainFriendlyName);

            if (source != null)
            {
                xml.WriteElementString(DiagnosticStrings.SourceTag, CreateSourceString(source));
            }

            if (trace != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExtendedDataTag);
                xml.WriteAttributeString(DiagnosticStrings.NamespaceTag, trace.EventId);

                trace.WriteTo(xml);

                xml.WriteEndElement();
            }

            if (exception != null)
            {
                xml.WriteStartElement(DiagnosticStrings.ExceptionTag);
                AddExceptionToTraceString(xml, exception);
                xml.WriteEndElement();
            }

            xml.WriteEndElement();
        }
 public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
 {
     string eventSource = null;
     string extendedData = null;
     string serializedException = null;
     if (source != null)
     {
         eventSource = CreateSourceString(source);
     }
     if (traceRecord != null)
     {
         StringBuilder sb = new StringBuilder();
         XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb, CultureInfo.CurrentCulture));
         writer.WriteStartElement("ExtendedData");
         traceRecord.WriteTo(writer);
         writer.WriteEndElement();
         extendedData = sb.ToString();
     }
     if (exception != null)
     {
         serializedException = ExceptionToTraceString(exception);
     }
     if (getServiceReference && (traceAnnotation != null))
     {
         return new TracePayload(serializedException, eventSource, appDomainFriendlyName, extendedData, traceAnnotation());
     }
     return new TracePayload(serializedException, eventSource, appDomainFriendlyName, extendedData, string.Empty);
 }
示例#7
0
		public TracePayload GetSerializedPayload(object source, TraceRecord traceRecord, Exception exception, bool getServiceReference)
		{
			string str = null;
			string str1 = null;
			string traceString = null;
			if (source != null)
			{
				str = DiagnosticTraceBase.CreateSourceString(source);
			}
			if (traceRecord != null)
			{
				StringBuilder stringBuilder = EtwDiagnosticTrace.StringBuilderPool.Take();
				try
				{
					using (StringWriter stringWriter = new StringWriter(stringBuilder, CultureInfo.CurrentCulture))
					{
						using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
						{
							xmlTextWriter.WriteStartElement("ExtendedData");
							traceRecord.WriteTo(xmlTextWriter);
							xmlTextWriter.WriteEndElement();
							xmlTextWriter.Flush();
							stringWriter.Flush();
							str1 = stringBuilder.ToString();
						}
					}
				}
				finally
				{
					EtwDiagnosticTrace.StringBuilderPool.Return(stringBuilder);
				}
			}
			if (exception != null)
			{
				traceString = EtwDiagnosticTrace.ExceptionToTraceString(exception, 0x7000);
			}
			if (!getServiceReference || EtwDiagnosticTrace.traceAnnotation == null)
			{
				return new TracePayload(traceString, str, DiagnosticTraceBase.AppDomainFriendlyName, str1, string.Empty);
			}
			else
			{
				return new TracePayload(traceString, str, DiagnosticTraceBase.AppDomainFriendlyName, str1, EtwDiagnosticTrace.traceAnnotation());
			}
		}
 private void BuildTrace(PlainXmlWriter xml, TraceEventType type, string msdnTraceCode, string description, TraceRecord trace, Exception exception, object source)
 {
     xml.WriteStartElement("TraceRecord");
     xml.WriteAttributeString("xmlns", "http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord");
     xml.WriteAttributeString("Severity", LookupSeverity(type));
     xml.WriteElementString("TraceIdentifier", msdnTraceCode);
     xml.WriteElementString("Description", description);
     xml.WriteElementString("AppDomain", this.AppDomainFriendlyName);
     if (source != null)
     {
         xml.WriteElementString("Source", CreateSourceString(source));
     }
     if (trace != null)
     {
         xml.WriteStartElement("ExtendedData");
         xml.WriteAttributeString("xmlns", trace.EventId);
         trace.WriteTo(xml);
         xml.WriteEndElement();
     }
     if (exception != null)
     {
         xml.WriteStartElement("Exception");
         this.AddExceptionToTraceString(xml, exception);
         xml.WriteEndElement();
     }
     xml.WriteEndElement();
 }