创建日志文件

mac2022-06-30  27

string date = DateTime.Now.ToString("yyyy-MM-dd"); string rootPath = System.Environment.CurrentDirectory; //string folderPath = rootPath + @"\Logs"; string folderPath = @"D:\\Logs"; string logPath = folderPath + "\\" + date + @".txt"; if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } if (!File.Exists(logPath)) { File.Create(logPath); } FileStream fileStream = new FileStream(logPath, FileMode.Append); StreamWriter writer = new StreamWriter(fileStream); string currentTime = DateTime.Now.ToString(); writer.WriteLine("【" + currentTime + "】:" + str); writer.Dispose(); writer.Close(); fileStream.Dispose(); fileStream.Close();

 

转载于:https://www.cnblogs.com/shenchao/p/3915018.html

相关资源:VC 如何生成日志
最新回复(0)