本地日志文件
写入Txt文件方法
1 private static void WriteTxt(string fullFilepath, string Content) 2 { 3 StreamWriter Sw1 = null; 4 try 5 { 6 7 CreatePath(GetFilePath(fullFilepath)); 8 Sw1 = new StreamWriter(fullFilepath, true, Encoding.UTF8); 9 { 10 Sw1.WriteLine(Content); 11 } 12 } 13 catch (Exception ef) 14 { 15 throw new Exception(ef.Message); 16 } 17 finally 18 { 19 try 20 { 21 Sw1.Close(); 22 } 23 catch 24 { 25 } 26 } 27 }去出文件所有路径
1 public static string GetFilePath(string FileName) 2 { 3 string sFile = FileName; 4 sFile = sFile.Substring(0, sFile.LastIndexOf("\\")); 5 return sFile; 6 }创建路径
1 public static bool CreatePath(string path) 2 { 3 try 4 { 5 if (!HasFilePath(GetFilePath(path))) 6 { 7 CreatePath(GetFilePath(path)); 8 } 9 Directory.CreateDirectory(path); 10 return true; 11 } 12 catch (Exception ee) 13 { 14 throw new Exception(ee.Message); 15 } 16 }文件所在路径是否存在
1 public static bool HasFilePath(string FileName) 2 { 3 if ((FileName.Length == 2) && (FileName.LastIndexOf(':') > 0)) 4 return true; 5 return Directory.Exists(GetFilePath(FileName)); 6 }