SimpleLogger.SimpleLog.ConvertXmlToPlainText C# (CSharp) Method

ConvertXmlToPlainText() private static method

Convert xmlEntry to plain text to be written to a file.
A typical xml entry to be converted looks like this: Entering method. See Source which method is meant. Something went wrong. Object reference not set to an instance of an object. at SimpleLogDemo.Program.DoSomethingElse(String fred) in D:\Projekt\VisualStudio\SimpleLogDemo\SimpleLogDemo\Program.cs:line 91 ]]> This is a basic implementation so far. Feel free to implement your own if you need something more sophisticated, e.g. nicer exception formatting.
private static ConvertXmlToPlainText ( System.Xml.Linq.XElement xmlEntry ) : string
xmlEntry System.Xml.Linq.XElement The XML entry to convert.
return string
        private static string ConvertXmlToPlainText(XElement xmlEntry)
        {
            var sb = new StringBuilder();

            foreach(var element in xmlEntry.DescendantsAndSelf())
            {
                if(element.HasAttributes)
                {
                    foreach(var attribute in element.Attributes())
                    {
                        if(sb.Length > 0)
                            sb.Append(TextSeparator);

                        sb.Append(attribute.Name).Append(" = ").Append(attribute.Value);
                    }
                }
                else
                {
                    if(sb.Length > 0)
                        sb.Append(TextSeparator);

                    // Remove new lines to get all in one line.
                    string value = element.Value.Replace("\r\n", " ");
                    sb.Append(element.Name).Append(" = ").Append(value);
                }
            }

            return sb.ToString();
        }