Exemple #1
0
        private static void RecordAppData(string fileName, string content)
        {
            try
            {
                FolderService.AssureAppDataFolder();

                var appDataFilePath = FolderService.GetAppDataFilePath(fileName);

                UpdateText(appDataFilePath, content);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Failed to record log to AppData.\r\n{ex}");
            }
        }
Exemple #2
0
        public static async Task RecordAsync(string fileName, string result)
        {
            try
            {
                var content = $"[Date: {DateTime.Now:HH:mm:ss fff}]" + Environment.NewLine
                              + result.TrimEnd() + Environment.NewLine + Environment.NewLine;

                FolderService.AssureAppDataFolder();

                var filePath = FolderService.GetAppDataFilePath(fileName);

                if (File.Exists(filePath) && (File.GetLastWriteTime(filePath) < DateTime.Now.AddHours(-1)))
                {
                    FolderService.Delete(filePath);
                }

                using (var sw = new StreamWriter(filePath, true, Encoding.UTF8))                 // BOM will be emitted.
                    await sw.WriteAsync(content);
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"Failed to record log to AppData.\r\n{ex}");
            }
        }