static string GetExceptionData(Exception exception)
        {
            StringBuilder sb = StringBuilderPool.Take();

            try
            {
                using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                {
                    using (XmlTextWriter xml = new XmlTextWriter(stringWriter))
                    {
                        xml.WriteStartElement(DiagnosticStrings.DataItemsTag);
                        foreach (object dataItem in exception.Data.Keys)
                        {
                            xml.WriteStartElement(DiagnosticStrings.DataTag);
                            xml.WriteElementString(DiagnosticStrings.KeyTag, XmlEncode(dataItem.ToString()));
                            xml.WriteElementString(DiagnosticStrings.ValueTag, XmlEncode(exception.Data[dataItem].ToString()));
                            xml.WriteEndElement();
                        }
                        xml.WriteEndElement();
                        xml.Flush();
                        stringWriter.Flush();

                        return(sb.ToString());
                    }
                }
            }
            finally
            {
                StringBuilderPool.Return(sb);
            }
        }
Example #2
0
        private static string GetInnerException(Exception exception, int remainingLength, int remainingAllowedRecursionDepth)
        {
            if (remainingAllowedRecursionDepth < 1)
            {
                return(null);
            }

            StringBuilder sb = StringBuilderPool.Take();

            try
            {
                using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                {
                    using (XmlWriter xml = XmlWriter.Create(stringWriter))
                    {
                        if (!WriteStartElement(xml, DiagnosticStrings.InnerExceptionTag, ref remainingLength))
                        {
                            return(null);
                        }

                        WriteExceptionToTraceString(xml, exception.InnerException, remainingLength, remainingAllowedRecursionDepth);
                        xml.WriteEndElement();
                        xml.Flush();
                        stringWriter.Flush();

                        return(sb.ToString());
                    }
                }
            }
            finally
            {
                StringBuilderPool.Return(sb);
            }
        }
Example #3
0
        public static void LogNewArchetype(ChunkTrace chunk)
        {
            StringBuilder stringBuilder = StringBuilderPool.Take();

            stringBuilder.Append("new ");
            ArchetypeToString(stringBuilder, chunk);

            LogChange(stringBuilder.ToString());

            StringBuilderPool.Release(stringBuilder);
        }
Example #4
0
        public static void LogDestroyedEntities(ChunkTrace chunk)
        {
            StringBuilder stringBuilder = StringBuilderPool.Take();

            stringBuilder.Append("destroyed entity/entities of ");
            ArchetypeToString(stringBuilder, chunk);

            LogChange(stringBuilder.ToString());

            StringBuilderPool.Release(stringBuilder);
        }
Example #5
0
        public static void LogModifiedComponent(ChunkTrace chunk, ComponentType type)
        {
            StringBuilder stringBuilder = StringBuilderPool.Take();

            stringBuilder.Append("modified component ");
            stringBuilder.Append(type);
            stringBuilder.Append(" of ");
            ArchetypeToString(stringBuilder, chunk);

            LogChange(stringBuilder.ToString());

            StringBuilderPool.Release(stringBuilder);
        }
        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));
        }
        static string BuildTrace(ref EventDescriptor eventDescriptor, string description, TracePayload payload, string msdnTraceCode)
        {
            StringBuilder sb = StringBuilderPool.Take();

            try
            {
                using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                {
                    using (XmlTextWriter writer = new XmlTextWriter(stringWriter))
                    {
                        writer.WriteStartElement(DiagnosticStrings.TraceRecordTag);
                        writer.WriteAttributeString(DiagnosticStrings.NamespaceTag, EtwDiagnosticTrace.TraceRecordVersion);
                        writer.WriteAttributeString(DiagnosticStrings.SeverityTag,
                                                    TraceLevelHelper.LookupSeverity((TraceEventLevel)eventDescriptor.Level, (TraceEventOpcode)eventDescriptor.Opcode));
                        writer.WriteAttributeString(DiagnosticStrings.ChannelTag, EtwDiagnosticTrace.LookupChannel((TraceChannel)eventDescriptor.Channel));

                        writer.WriteElementString(DiagnosticStrings.TraceCodeTag, msdnTraceCode);
                        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();
                        writer.Flush();
                        stringWriter.Flush();

                        return(sb.ToString());
                    }
                }
            }
            finally
            {
                StringBuilderPool.Return(sb);
            }
        }
    protected string InsertAdditionalUsings(string scriptContent, string[] additionalUsings)
    {
        StringBuilder stringBuilder = StringBuilderPool.Take();

        foreach (string additionalUsing in additionalUsings)
        {
            if (!scriptContent.Contains(additionalUsing))
            {
                stringBuilder.AppendLine(additionalUsing);
            }
        }

        stringBuilder.AppendLine(scriptContent);

        string result = stringBuilder.ToString();

        StringBuilderPool.Release(stringBuilder);

        return(result);
    }
Example #9
0
        internal static string ExceptionToTraceString(Exception exception, int maxTraceStringLength)
        {
            StringBuilder sb = StringBuilderPool.Take();

            try
            {
                using (StringWriter stringWriter = new StringWriter(sb, CultureInfo.CurrentCulture))
                {
                    using (XmlWriter xml = XmlWriter.Create(stringWriter))
                    {
                        WriteExceptionToTraceString(xml, exception, maxTraceStringLength, MaxExceptionDepth);
                        xml.Flush();
                        stringWriter.Flush();

                        return(sb.ToString());
                    }
                }
            }
            finally
            {
                StringBuilderPool.Return(sb);
            }
        }