public static async Task <string> ReadAsync(string fileName) { string result = string.Empty; try { await _semaphore.WaitAsync().ConfigureAwait(false); result = await Read2Async(fileName).ConfigureAwait(false); } catch (FileNotFoundException exc0) { //put up with it: it may be the first time we use this file Debug.WriteLine("no worries but: " + exc0.ToString()); } catch (Exception exc) { if (SemaphoreSlimSafeRelease.IsAlive(_semaphore)) { Debug.WriteLine("ERROR in Logger.ReadAsync(): " + exc.ToString()); } } finally { SemaphoreSlimSafeRelease.TryRelease(_semaphore); } return(result); }
public static void ClearAll() { Task.Run(async delegate { try { await _semaphore.WaitAsync().ConfigureAwait(false); //await _logsFolder.DeleteAsync().AsTask().ConfigureAwait(false); _logsFolder = await ApplicationData.Current.LocalCacheFolder.CreateFolderAsync(LogFolderName, CreationCollisionOption.ReplaceExisting).AsTask().ConfigureAwait(false); } catch (Exception exc) { if (SemaphoreSlimSafeRelease.IsAlive(_semaphore)) { Debug.WriteLine("ERROR in Logger.ClearAll(): " + exc.ToString()); } } finally { SemaphoreSlimSafeRelease.TryRelease(_semaphore); } }); }
private static async Task Add2Async(string msg, string fileName) { try { await _semaphore.WaitAsync().ConfigureAwait(false); await UpdateLogAsync(fileName, msg).ConfigureAwait(false); //Debug.WriteLine("the thread id is " + Environment.CurrentManagedThreadId + " after the await"); } catch (Exception exc) { if (SemaphoreSlimSafeRelease.IsAlive(_semaphore)) { Debug.WriteLine("ERROR in Logger: " + exc.ToString()); } } finally { SemaphoreSlimSafeRelease.TryRelease(_semaphore); } // await SendEmailWithLogsAsync("*****@*****.**"); // maybe move Logger into the utils and use the right email address and maybe new parameter "sendemailifcrash" // On second thought, the email could be annoying and scary. Better leave the option to send it in the "About" panel only. }