For something like this, what comes to mind is a comma-separated or tab-separated file. These will be human-readable in notepad, or you can bring it into Excel, and make graphs of the data. (Though I'm sure someone out there will consider CSV or tab-SV to be far away from 'best practice'. However, it's simple to implement, simple to read, and readable in hundreds of apps. That's a pretty darned good practice in my book.)
You can do something similar to this:
FileStream^ textFileStream = gcnew FileStream(logFileName, FileMode::Append, FileAccess::Write, FileShare::Read);
StreamWriter^ textFileWriter = gcnew StreamWriter(textFileStream, Encoding::Unicode);
textFileWriter->AutoFlush = true;
- For a timestamp, just dump out
DateTime::Now->ToString()
.
- See above for some objects you can use. Use String::Format and send the output to the StreamWriter, that'll give you a verbose, human-readable log.
- If you're worried about what happens if your program crashes, don't worry about that too much. The StreamWriter as initialized above will write through to the FileStream as you use it, which will in turn write to the filesystem. This won't do a filesystem-level flush, only a filesystem-level write (the data will be in the OS's write-back cache, to be flushed to disk at some point in the next few seconds), so if the OS crashes, your log file will be incomplete, but a program crash will be handled file.
- There are various logging frameworks available for .Net, which you can use from C++/CLI, but I'm not too familiar with them.
- Even if you're logging the data each second, it's doubtful that you need to worry about batching up the data. Let's say you had hundreds of motors to write data for: that's what, 1 kilobyte per second? maybe 2? Just write the data out as needed. (If you want to minimize disk/CPU usage, consider just logging the data less frequently, once per 10 seconds or once per minute.)