编程的时候,很多时候需要简单些一些log或记录参数之类的,这里提供个方法。
private void WriteTxt(string info)
{
var path = AppDomain.CurrentDomain.BaseDirectory;
path = System.IO.Path.Combine(path, "Data Log");
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
using (var stream = new StreamWriter(System.IO.Path.Combine(path, $"Data_{DateTime.Now:yyyyMMdd}.txt"), true))
{
stream.WriteLine("{0:yyyy-MM-dd HH:mm:ss}, Info{1}",DateTime.Now, info);
}
}
本文介绍了一种简单的日志记录方法,通过C#代码实现,能够自动创建日期格式的日志文件,并将信息写入到相应的文件中,方便进行调试及后期的数据分析。
362

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



