C# 一些代码小结--使用文件记录日志
public class FaceLog
{
public static void AppendInfoLog(string errMsg)
{
try
{
string Folder = ".\log\";
string fileName = Folder + "Info_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
if (!System.IO.Directory.Exists(Folder))
System.IO.Directory.CreateDirectory(Folder);
if (!File.Exists(fileName))
{
FileStream stream = System.IO.File.Create(fileName);
stream.Close();
stream.Dispose();
}
using (TextWriter fs = new StreamWriter(fileName, true))
{
fs.Write(errMsg);
fs.Close();
fs.Dispose();
}
}
catch
{
}
}
public static void AppendSerialLog(string errMsg)
{
try
{
string Folder = ".\log\";
string fileName = Folder + "Serial_" + DateTime.Now.ToString("yyyyMMdd") + ".txt";
if (!System.IO.Directory.Exists(Folder))
System.IO.Directory.CreateDirectory(Folder);
if (!File.Exists(fileName))
System.IO.File.Create(fileName);
using (TextWriter fs = new StreamWriter(fileName, true))
{
fs.Write(errMsg);
fs.Close();
fs.Dispose();
}
}
catch
{
}
}
}
声明:该内容转自:https://www.cnblogs.com/wangboke/p/5854144.html