FormatLogMessageWithXmlContent static method

String FormatLogMessageWithXmlContent(
  1. String entryKind,
  2. MemoryStream memoryStream
)
Format XML content in a MemoryStream for message. Kind of the entry. The memory stream.

Implementation

static String FormatLogMessageWithXmlContent(
    String entryKind, MemoryStream memoryStream) {
  // todo("improve FormatLogMessageWithXmlContent")
//    print(".. improve FormatLogMessageWithXmlContent");
  return utf8.decode(memoryStream.AllElements);
//            StringBuffer sb = new StringBuffer();
//            XmlReaderSettings settings = new XmlReaderSettings();
//            settings.ConformanceLevel = ConformanceLevel.Fragment;
//            settings.IgnoreComments = true;
//            settings.IgnoreWhitespace = true;
//            settings.CloseInput = false;
//
//            // Remember the current location in the MemoryStream.
//            long lastPosition = memoryStream.Position;
//
//            // Rewind the position since we want to format the entire contents.
//            memoryStream.Position = 0;
//
//            try
//            {
//                using (XmlReader reader = XmlReader.Create(memoryStream, settings))
//                {
//                    using (StringWriter writer = new StringWriter(sb))
//                    {
//                        using (XmlTextWriter xmlWriter = new XmlTextWriter(writer))
//                        {
//                            xmlWriter.Formatting = Formatting.Indented;
//
//                            EwsUtilities.WriteTraceStartElement(xmlWriter, entryKind, true);
//
//                            while (!reader.EOF)
//                            {
//                                xmlWriter.WriteNode(reader, true);
//                            }
//
//                            xmlWriter.WriteEndElement(); // Trace
//                            xmlWriter.WriteWhitespace(Environment.NewLine);
//                        }
//                    }
//                }
//            }
//            catch (XmlException)
//            {
//                // We tried to format the content as "pretty" XML. Apparently the content is
//                // not well-formed XML or isn't XML at all. Fallback and treat it as plain text.
//                sb.Length = 0;
//                memoryStream.Position = 0;
//                sb.Append(Encoding.UTF8.GetString(memoryStream.GetBuffer(), 0, (int)memoryStream.Length));
//            }
//
//            // Restore Position in the stream.
//            memoryStream.Position = lastPosition;
//
//            return sb.ToString();
}