Our customized logging sysem saves info into a xml file, like this:
<?xml version="1.0" standalone="yes"?>
<log>
<entry> msg </entry>
<entry> msg </entry>
.
.
.
</log>
Right now we are using StreamWriter to write. If the system crashes (we are in the middle of the development), the end tag/element, </log>, will not be written to the file so the xml file cannot be opened correct with IE. I found there are two possible options to correct this:
Option A: write the end tag at very beginning when file is initialized and then do "insert" for each new entry. right now we are doing "append".
Option B: change to XmlDocument or XmlWriter.
In option A, change "append" to "insert", we need to keep the current location, which is right before the end tag, </log>,. And write from that current location. I didn't find a good way to do this.
In option B, the XmlWriter is almost the same as other stream/writer. No easy way to "insert". The XmlDocument is easy to "insert", but there is no Flush() method to call. we have to Save() to make it write to file. If the Save() means close the stream/file, I don't want to do Load() and Save() for each entry. that will be too expensive, I think.
do you have any good idea about this?
<entry>elements? That will always be a well-formed document fragment, which your system could splice in between<log>tags before you view it.