I have a program that periodically polls a certain folder for log files. When it finds a log file, it reads it, does whatever it has to, and moves on. The program that writes the log files keeps appending, not overwriting, so I store a last modified date and a bookmark line, which is wherever I got up to last time I read the file. All good so far.
Now, I want to persist my bookmark info, so that if I shut down the polling app and restart it, it doesn’t start again at the beginning of every log file. I don’t want to hassle about storing the info in the DB; a simple XML file will do. So I thought about storing the info in the app.config file.
First question is, is this a Wrong Thing To Do? Is app.config meant only to be read from, not written to at runtime? In which case, the logical answer would be simply to write a separate xml file?
Second, if it’s OK to do this: I found a nice blog post about how to make a custom config section, but it seems to screw up other parts of the app that try to read the config file using ConfigurationManager.AppSettings.Get(key), with a ConfigurationErrorsException, message = “Configuration system failed to initialize”. What to do about that?
I’d store this as a separate file from the app.config – it doesn’t seem like configuration data to me. You could use Xml Serialization, Yaml, Json, or even (please, god, no) binary serialization, and either store it alongside the exe (if you have write permissions there) or somewhere from the Environment.SpecialFolder enumeration.