// Create an XML writerSystem.Text.StringBuilder stringBuilder = new System.Text.StringBuilder(1000);
System.IO.StringWriter stringWriter = new StringWriter(stringBuilder);
System.Xml.XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.Formatting = System.Xml.Formatting.Indented;
xmlWriter.Indentation = 5; //optionally adjust the indentation
// Write out configuration settings
it turned out that the issue was simply that I was using xmlWriter.WriteRaw instead of xmlWriter.WriteElementString. the latter will respect System.Xml.Formatting.Indented and is cleaner code anyway.
to crush this bug, all I had to do was replace the last line (and other similar lines) with this: