using System;
using System.IO;
using System.Text;
namespace Spider
{
public class LogInfo
{
private static string logPath = @"logs\";
public static void WriteLog(string message)
{
DateTime logTime = DateTime.Now;
string logFile = "log" + logTime.ToShortDateString() + ".txt";
try
{
FileStream fs = new FileStream(logPath + logFile, FileMode.Append);
StreamWriter sw = new StreamWriter(fs);
try
{
sw.WriteLine("时间:" + logTime.ToString());
sw.WriteLine(message);
sw.WriteLine();
sw.Flush();
}
catch (Exception ex)
{
Console.WriteLine("日志文件写入失败:" + ex.ToString());
}
finally
{
sw.Close();
sw = null;
fs.Close();
fs = null;
}
}
catch (Exception ex)
{
Console.WriteLine("日志文件打开失败:" + ex.ToString());
}
}
}
}