1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.IO;
- namespace Common
- {
- public class FilesHelper
- {
- public static void WriteFile(string path, string data)
- {
- using (var fs = new FileStream(path, FileMode.Append))
- {
- using (var sw = new StreamWriter(fs))
- {
- sw.WriteLine(data);
- sw.Flush();
- }
- }
- }
- public static string ReaderFile(string path)
- {
- using (var sw = new StreamReader(path))
- {
- return sw.ReadToEnd();
- }
- }
- public static void LogBD(string content, string pathName = "", string directoryName = "Log")
- {
- if (pathName.IsEmpty())
- pathName = content;
- var path = AppDomain.CurrentDomain.BaseDirectory + "/" + directoryName;
- CreateDirectory(path);
- path += $"/{DateTime.Now.ToString("yyyyMMdd")}";
- CreateDirectory(path);
- WriteFile(path + $"/{pathName}.txt", content + " || " + DateTime.Now.ToString());
- }
-
-
-
-
- private static void CreateDirectory(string path)
- {
- if (!Directory.Exists(path))
- Directory.CreateDirectory(path);
- }
- }
- }
|