标签:\n toe sha 方法 catch path datetime sage demo
写日志的方法:
public static void WriteLog(Exception e) { try { var fileName = DateTime.Now.ToString("HH:mm:ss").Replace(‘ ‘, ‘_‘).Replace(‘:‘,‘_‘); var physicalPath = "E:/本机demo/ConsoleApp2/log/"+DateTime.Now.ToString("yyyy-MM-dd")+"/Exceptionlog_" + fileName + ".log"; if (!File.Exists(physicalPath)) { var fcreat = File.Create(physicalPath); fcreat.Close(); } using (FileStream aFile = new FileStream(physicalPath, FileMode.Open)) { StreamReader sr = new StreamReader(aFile, Encoding.GetEncoding("GB2312")); var content = sr.ReadToEndAsync().Result; #region 写入异常信息 using (StreamWriter sw = new StreamWriter(aFile, Encoding.UTF8)) { sw.Write(content + "\r\n" + DateTime.Now.ToString() + ":\r\n" + e.Message.ToString()); //这里是写入的内容 sw.Flush(); sw.Close(); } #endregion sr.Close(); } } catch (Exception ex) { throw (ex); } }
标签:\n toe sha 方法 catch path datetime sage demo
原文地址:https://www.cnblogs.com/yuchenghao/p/9443318.html