I have a class that needs to be constantly serialized, because the info is read from a file outside of my app. My info classes can be represented by something like this:
[XmlRoot("log")]
public class Log
{
[XmlArray("infos")]
[XmlArrayItem("info")]
public List<Item> Infos { get; set; }
}
public class Item
{
[XmlElement("time")]
public DateTime Time { get; set; }
[XmlElement("info")]
public string Info { get; set; }
}
My problem is that every time I add a new element must write the full file, and this is creating unwanted performance. Something like this:
var serializer = new XmlSerializer(typeof(Log));
stream.SetLength(0);
serializer.Serialize(stream, log);
I've tried removing the cleaning process before writing but made no difference to performance.performance. Does anyone have an idea to improve the performance?
EDITED
The number of elements in this collection exceeds 100,000.