在没有引入log4j.dll 的情况下,简单输出日志:
public static void ErrorLog(string mssg)
{
string FilePath = "F:/ErrorLog.txt";
StreamWriter tw = null;
try
{
if (!File.Exists(FilePath))
{
File.Create(FilePath);
}
if (System.IO.File.Exists(FilePath))
{
using (tw = System.IO.File.AppendText(FilePath))
{
tw.WriteLine(DateTime.Now.ToString() + "> " + mssg);
tw.Flush();
}
}
else
{
tw = new StreamWriter(FilePath);
tw.WriteLine(DateTime.Now.ToString() + "> " + mssg);
}
}
catch (Exception ex)
{ }
finally
{
if (tw != null)
tw.Close();
}
}
本文介绍了一种在未使用log4j的情况下,通过C#实现的日志记录方法,该方法可以将错误信息写入到指定的文本文件中,包括当前时间和错误消息。
823

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



