I use XML Writer to create a log of important events in my application.
Everything is working fine now, assuming the application is closed correctly, but if it is not, the file is not closed and the log is mostly lost.
Suppose a simple element entry is something like this:
writer.WriteStartElement(eventName);
writer.WriteAttributeString("t", DateTime.Now.ToString());
writer.WriteString(eventBody);
writer.WriteEndElement();
Is there a way to close the file at this point and add the remaining elements to it later and only then close the root element and the XML writer?
source
share