1.採用打開創建的方式,同名寫入,不同名創建 ,最近接手一個項目,一些好用的日誌組件領導不也不用,自己寫唄
void WriteLogFile(string Content)
{
string strFoloder = AppDomain.CurrentDomain.BaseDirectory + "\\applogs";
if (!Directory.Exists(strFoloder))
{
Directory.CreateDirectory(strFoloder);
}
string strFileName = DateTime.Now.ToString("yyyyMMdd") + ".txt";
FileStream fs = new FileStream(strFoloder + "\\" + strFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
StreamWriter m_streamWriter = new StreamWriter(fs);
m_streamWriter.BaseStream.Seek(0, SeekOrigin.End);
m_streamWriter.WriteLine(Content);
m_streamWriter.Flush();
m_streamWriter.Close();
fs.Close();
}