I am making an error logging library which creates a file in a specified location, then saves the error information in that file, which can then be read by a separate tasker program that I intend to write in conjunction with this library.
The way that I'm saving it is in Binary Format (using BinaryFormatter()
and FileStream()
), where I serialize a class called ErrorEntry into the file and append it to the end of the file. What this means is that I have a series of ErrorEntries back to back. I don't have it as a list because it doesn't seem practicle to have to read all the information into a list from the file, add an entry, then save it back to the file and dump the resources. It seems much more effective to only have to do a single write command, and just store each one as its own object that is serialized.
My problem is that I can find several examples on serializing lists or individual objects, but nothing on multiple - but separate - objects. Although I want to save them as individual objects, when I load them I want to read the object and return the series as a list of that object. I imagine that there is something similar to
while(!EOF)
{
//deserialize each object
//add individual object to a list
}
//return the list of objects
How would I go about deserializing each object from a single file? Does it have an internal marker that the above works and I simply need to detect whether it's the end of the file, or do I need to do something else to read them?