public static void Write(string context)
{
string fileName = Path + DateTime.Now.ToString("yyyyMMdd") + "//GateWayLog" + DateTime.Now.ToString("HH") + ".txt";
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(fileName));
System.IO.TextWriter output = null;
try
{
output = TextWriter.Synchronized(System.IO.File.AppendText(fileName));
output.Write(context);
}
catch { }
finally
{
if (output != null)
{
output.Close();
}
}
}
/// <summary>
/// Writes the log.
/// </summary>
/// <param name="Message">The message.</param>
private void WriteLog(string Message)
{
Log.Write(Message + Environment.NewLine + Environment.NewLine);
}
最后取页面调用WriteLog方法就可以
本文介绍了一种简单的日志记录方法实现,通过创建文件并追加写入的方式记录日志,支持按日期和时间自动创建日志文件。
350

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



