C# 生成txt文件
/// <summary>
/// 记录日志
/// </summary>
/// <param name="message">信息</param>
public static void RecordLog(string message)
{
try
{
string filePath = "D:\\Monitor\\MonitorLog.txt";
if (!File.Exists(filePath))
{
File.Create(filePath).Close();
}
using (StreamWriter w = File.AppendText(filePath))
{
w.WriteLine("{0}:{1}", DateTime.Now.ToString("yy/MM/dd HH:mm:ss"), message);
w.Flush();
w.Close();
}
}
catch (Exception ex)
{
}
}
3736

被折叠的 条评论
为什么被折叠?



