/// <summary>
/// 保存日志
/// </summary>
/// <param name="_filenum">日志文件名</param>
/// <param name="_content">日志内容</param>
public static void saveLogFiles(string _filenum, string _content)
{
StreamWriter sw = null;
//保存的日志文件名
string FileName = FileName = HttpContext.Current.Server.MapPath("~/Logs/" + DateTime.Now.ToString("yyyy.MM.dd") + "-" + _filenum + ".log");
try
{
#region 检测日志目录是否存在,不存在则创建
if (!Directory.Exists(HttpContext.Current.Server.MapPath("~/Logs")))
{
Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/Logs"));
}
#endregion
if (!File.Exists(FileName))
sw = File.CreateText(FileName); //不存在此文件则是创建内容(原有内容消失)
else
sw = File.AppendText(FileName); //存在此文件则是追加内容
sw.WriteLine("\r\n" + System.DateTime.Now + ":\r\n" + _content);
sw.Flush();
}
finally
{
if (sw != null)
sw.Close();
}
}
创建日志文件
最新推荐文章于 2022-05-22 14:47:56 发布