编程语言
首页 > 编程语言> > C# 随笔写txt

C# 随笔写txt

作者:互联网

public static void WriterFile(string file)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
//如果不存在,则创建目录
if (!Directory.Exists(path + "Log/"))
{
Directory.CreateDirectory(path + "Log/");
}
FileStream fs = new FileStream(path + "\\Log/log" + DateTime.Now.ToString("yyyyMMdd") + ".txt", FileMode.Append);
StreamWriter streamWriter = new StreamWriter(fs);
streamWriter.BaseStream.Seek(0, SeekOrigin.End);
streamWriter.WriteLine(DateTime.Now.ToString() + " " + file);
streamWriter.Flush();
streamWriter.Close();
fs.Close();



}

标签:streamWriter,随笔,Log,C#,DateTime,FileStream,fs,path,txt
来源: https://www.cnblogs.com/codeadmin/p/11243747.html