调用
WriteTextLog("", db.SW_Registration.Count().ToString(), DateTime.Now);
方法
public static void WriteTextLog(string action, string strMessage, DateTime time)
{
string path = AppDomain.CurrentDomain.BaseDirectory + @"\Log\";
if (!System.IO.Directory.Exists(path))
System.IO.Directory.CreateDirectory(path);
string fileFullPath = path + time.ToString("yyyy-MM-dd") + ".System.txt";
StringBuilder str = new StringBuilder();
str.Append("Time: " + time.ToString() + "\r\n");
str.Append("Action: " + action + "\r\n");
str.Append("Message: " + strMessage + "\r\n");
str.Append("-----------------------------------------------------------\r\n\r\n");
System.IO.StreamWriter sw;
if (!File.Exists(fileFullPath))
{
sw = File.CreateText(fileFullPath);
}
else
{
sw = File.AppendText(fileFullPath);
}
sw.WriteLine(str.ToString());
sw.Close();
}