我必须将我的应用程序事件和异常记录在文档文件夹中 win 8 应用程序的文件中
Windows.Storage.StorageFolder localFolder = KnownFolders.DocumentsLibrary;
问题是当我一个接一个地调用 WriteToFile 函数时,由于该文件仍在使用中,因此出现访问被拒绝异常。有没有办法使这项工作
public async void WriteToFile(string log)
{
try
{
StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt", CreationCollisionOption.OpenIfExists);
//StorageFile sampleFile = await localFolder.GetFileAsync("dataFile.txt");
IRandomAccessStream writeStream = await sampleFile.OpenAsync(FileAccessMode.ReadWrite);
IOutputStream outputStream = writeStream.GetOutputStreamAt(writeStream.Size);
DataWriter dataWriter = new DataWriter(outputStream);
dataWriter.WriteString(log);
dataWriter.StoreAsync().AsTask().Wait();
outputStream.FlushAsync().AsTask().Wait();
}
finally
{
}
}