public class MyLog
{
public static void WriteLog(string error)
{
WriteLog(error, null);
}
public static void WriteLog(string error, Exception ex)
{
string dir = Application.StartupPath + "\\LOG";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
error = DateTime.Now.ToString() + " " + error + System.Environment.NewLine;
if (ex != null)
{
error += ex.ToString() + System.Environment.NewLine;
}
string logFilePath = dir + "\\log_" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
File.AppendAllText(logFilePath, error);
}
}
欢迎转载,转载请注明:转载自[ http://www.cnblogs.com/zjfree/ ]
浙公网安备 33010602011771号