这个方法是直接创建 根据 年-月-日.txt的日志.不用去下多余的包还行
public static void Wirtelog(string message)
{
try
{
string strToday = DateTime.Today.ToString("yyyy-MM-dd");
string LogPath = System.Configuration.ConfigurationManager.AppSettings["FilePath"] + "Log/";
string LogFile = LogPath + "/" + strToday + ".txt";
//文件夹不存在就创建
if (!Directory.Exists(LogPath))
{
Directory.CreateDirectory(LogPath);
}
//文件不存在就创建
if (!File.Exists(LogFile))
{
StreamWriter SW;
SW = File.CreateText(LogFile);
SW.Close();
}
//开始写日志
using (StreamWriter SW = File.AppendText(LogFile))
{
SW.WriteLine(DateTime.Now + " 日志 =【" + message + "】 ");
SW.Close();
}
}
catch
{
}
}