Hi, I'm using IsloatedStorage in a Silverlight app to log information on the client, and I added a function to clear the log file... However I have had problems with the two approaches I tried:
Approach one: use
IsolatedStorageFile.DeleteFile("log.log");
Result: This fails and returns an "[IsolatedStorage_DeleteFile]" error (No other info). The function works fine on test files, e.g. DeleteFile("test.txt"), but refuses to delete the log. I though that perhaps the log is being used, and tried to close it with
IsolatedStorageFileStream.close()
but this returns a different error "[IsolatedStorage_StoreNotOpen]"... :( I know it is open as the previous line of code successfully logs a message
Approach Two: Reopen the log file using the Truncate file mode-
_storageFileStream = new IsolatedStorageFileStream(logfilename, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite, _storageFile);
According to msdn, Truncate "Specifies that the operating system should open an existing file. Once opened, the file should be truncated so that its size is zero bytes." However, it opens my log file and fills it with blank space! The filesize is left identical, the next log message is appended to the end of all of the space.
Haven't found much useful info on these issues yet, cheers for any help!