c#实现日志
时间:2007-03-07 来源:twanger
用c#实现的一个日志操作版本(未考虑多线程)
public static void logger(String className, String optFlg, String msg)
{
filePath = ConfigurationManager.AppSettings["traceLogFilePath"];
fileName = filePath +"\\" + ConfigurationManager.AppSettings["traceLogFileName"];
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
} FileStream filestream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
writer = new StreamWriter(filestream, System.Text.Encoding.Default);
writer.BaseStream.Seek(0,SeekOrigin.End);
writer.Write("\r\n");
writer.WriteLine("{0} {1} {2} {3}", DateTime.Now.ToString(), className, optFlg, msg); writer.Flush();
writer.Close();
filestream.Close();
}
{
filePath = ConfigurationManager.AppSettings["traceLogFilePath"];
fileName = filePath +"\\" + ConfigurationManager.AppSettings["traceLogFileName"];
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
} FileStream filestream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);
writer = new StreamWriter(filestream, System.Text.Encoding.Default);
writer.BaseStream.Seek(0,SeekOrigin.End);
writer.Write("\r\n");
writer.WriteLine("{0} {1} {2} {3}", DateTime.Now.ToString(), className, optFlg, msg); writer.Flush();
writer.Close();
filestream.Close();
}
相关阅读 更多 +