private void SaveMessage(string message)
{
try
{
using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isolatedStorage.DirectoryExists("RaygunIO"))
{
isolatedStorage.CreateDirectory("RaygunIO");
}
int number = 1;
while (true)
{
bool exists = isolatedStorage.FileExists("RaygunIO\\RaygunErrorMessage" + number + ".txt");
if (!exists)
{
string nextFileName = "RaygunIO\\RaygunErrorMessage" + (number + 1) + ".txt";
exists = isolatedStorage.FileExists(nextFileName);
if (exists)
{
isolatedStorage.DeleteFile(nextFileName);
}
break;
}
number++;
}
if (number == 11)
{
string firstFileName = "RaygunIO\\RaygunErrorMessage1.txt";
if (isolatedStorage.FileExists(firstFileName))
{
isolatedStorage.DeleteFile(firstFileName);
}
}
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("RaygunIO\\RaygunErrorMessage" + number + ".txt", FileMode.OpenOrCreate, FileAccess.Write, isolatedStorage))
{
using (StreamWriter writer = new StreamWriter(isoStream, Encoding.Unicode))
{
writer.Write(message);
writer.Flush();
writer.Close();
}
}
System.Diagnostics.Debug.WriteLine("Saved message: " + "RaygunErrorMessage" + number + ".txt");
System.Diagnostics.Debug.WriteLine("File Count: " + isolatedStorage.GetFileNames("RaygunIO\\*.txt").Length);
}
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(string.Format("Error saving message to isolated storage {0}", ex.Message));
}
}