public static void WriteLogToFile(DictionaryEnum folder, string fileName, string message) { try { string path = CreateDictionary(folder, fileName); if (!File.Exists(path)) { using (var sw = File.CreateText(path)) { sw.WriteLineAsync(message); } } else { using (var sw = File.AppendText(path)) { sw.WriteLineAsync(message); } } } catch (Exception e) { throw e; } }
private static string CreateDictionary(DictionaryEnum folder, string fileName) { string path = Path.GetPathRoot(Environment.SystemDirectory); // var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); path = string.Concat(path, folder); if (folder == DictionaryEnum.Log) { path = string.Concat(path, "\\", DateTime.Now.ToString("MM-dd-yyyy")); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } path = string.Concat(path, "\\", fileName); return(path); }
private void DumpDictionary(DictionaryEnum en) { switch (en) { case DictionaryEnum.All: File.WriteAllText(DataDir + "Dictionary.json", JsonConvert.SerializeObject(CommentDictionary)); File.WriteAllText(DataDir + "CheckedComments.json", JsonConvert.SerializeObject(CheckedComments)); File.WriteAllText(DataDir + "CheckedPosts.json", JsonConvert.SerializeObject(CheckedPosts)); break; case DictionaryEnum.Comments: File.WriteAllText(DataDir + "CheckedComments.json", JsonConvert.SerializeObject(CheckedComments)); break; case DictionaryEnum.Posts: File.WriteAllText(DataDir + "CheckedPosts.json", JsonConvert.SerializeObject(CheckedPosts)); break; case DictionaryEnum.Dictionary: File.WriteAllText(DataDir + "Dictionary.json", JsonConvert.SerializeObject(CommentDictionary)); break; } }