I have a script that uses XML files as log files. For example...
Everytime I access A.aspx the script is ran and appends an entry containing the date/time and referrer to the xml file.
A major stripped down verion of the method is:
XmlDocument xmlDoc = new XmlDocument();
XmlElement entry = xmlDoc.CreateElement("entry");
xmlDoc.Load(logFile);
xmlDoc.DocumentElement.AppendChild(entry);
xmlDoc.Save(logFile);
My question is: If the server page is accessed almost simultaneously by two different users, how can I make sure that BOTH "entry" elements are added to the xml file? My fear is that User 1 loads the file immediately before User 2. User 1 appends the element and saves the file, then User 2 appends an element and saves the file again, but overwriting User 1's save, thus eliminating User 1's update to the log file. Again, how can I prevent this?
Thanks,
Joshua
Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.