I am implementing a log module for a win8 store app.
the basic idea is create a log object during run time and write log via logMessage("str to log") interface to write it in log file, either called from UI thread or backend thread.
I can make sure the StorageFile is created during runtime and the logMessage code just look like following:
void
LogEntity::InternalLogFunction(Platform::String^ logString) /* IN */
{
if(mLogFileHandler){
Windows::Storage::FileIO::AppendTextAsync(mLogFileHandler, logString);
}
}
During my running, I can see only one line or none of the text been written to the file. But if I add breakpoint on the AppendTextAsync call, I can see many many calls been reached.
Does this mean an async call can not be re-entered? and what's the proper way to fulfill my purpose?
I just tried another way to make it a little bit synchronized, but it will cause exception:
auto t = create_task(Windows::Storage::FileIO::AppendTextAsync(mLogFileHandler, logString));
t.wait();