/// <summary>
/// 写入日志到文本文件
/// </summary>
/// <param name="action">动作</param>
/// <param name="strMessage">日志内容</param>
/// <param name="time">时间</param>
public static void WriteTextLog(string action, string strMessage)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"SystemLog";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string fileFullPath = path + DateTime.Now.ToString("yyyy-MM-dd") + ".System.txt";
StringBuilder str = new StringBuilder();
str.Append("Time: " + DateTime.Now.ToString() + "
");
str.Append("Action: " + action + "
");
str.Append("Message: " + strMessage + "
");
str.Append("-----------------------------------------------------------
");
StreamWriter sw;
if (!File.Exists(fileFullPath))
{
sw = File.CreateText(fileFullPath);
}
else
{
sw = File.AppendText(fileFullPath);
}
sw.WriteLine(str.ToString());
sw.Close();
}