If you are using this as a log file which is likely to grow into the 10's or 100's of MB then yes, this is a very bad way of doing it as you need to load the entire file into memory each time you want to add something to it.
That is why most log files are just a glorified CSV file format.
If you really must use XML then a work around is to create a visitors.xml file which looks something like this:
Code:
<!DOCTYPE staticinc [ <!ENTITY logentries SYSTEM "visitors_log.xml"> ]>
<root>
&logentries;
</root>
And then the visitors_log.xml file can be treated as a simple text file and appended to quickly with your XML above.
Code:
StreamWriter sw = File.AppendText("visitors_log.xml");
sw.Write("<visitor>");
sw.Write("<name>" + name + "</name>");
sw.Write("<lastname>" + lastName + "</lastname>");
sw.WriteLine("</visitor>");
sw.Close();
Then if you need to process the log as a XML file you can call XmlDocument.Load on the visitors.xml file.
/- Sam Judson : Wrox Technical Editor -/