C# 日志
通常都用log4net
public static void WriteLog(string msg, string logName, string path){var Log = "";Log += msg + "\r\n";if (Directory.Exists(path) == false){Directory.CreateDirectory(path);}if (!System.IO.File.Exists(path + "/" + logName + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt")){FileStream fs1 = new FileStream(path + "/" + logName + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs1);sw.WriteLine(Log);sw.Close();fs1.Close();}else{FileStream fs = new FileStream(path + "/" + logName + "_Log" + DateTime.Today.ToString("yyyy-MM-dd") + ".txt" + "", FileMode.Append, FileAccess.Write);StreamWriter sr = new StreamWriter(fs);sr.WriteLine(Log);sr.Close();fs.Close();}}一天生成一個,根據名字可生成不同的日志。
?
轉載于:https://www.cnblogs.com/czly/p/10370670.html
總結
- 上一篇: 前嗅ForeSpider中数据采集界面介
- 下一篇: MySQL防止库存超卖方法总结