1、C#记录文本日志
public static void WriteLogs(string fileName,string Content){
string path = AppDomain.CurrentDomain.BaseDirectory;
if (!string.IsNullOrEmpty(path)) {
path = path + fileName;
//如果文件夹不存在,则创建文件夹
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
//如果当天日志文件不存在,则创建文件
path = path + "\\" + DateTime.Now.ToString("yyyyMMdd")+".txt";
if (!File.Exists(path)) {
FileStream fs = File.Create(path);
s.Close();
}
if (File.Exists(path)) {
StreamWriter sw = new StreamWriter(path,true,System.Text.Encoding.Default);
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ">>>" +content);
sw.WriteLine("....................分割线..................");
sw.Close();
}
}
}