欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C# 随笔写txt

程序员文章站 2022-05-27 10:01:56
public static void WriterFile(string file) { string path = AppDomain.CurrentDomain.BaseDirectory; //如果不存在,则创建目录 if (!Directory.Exists(path + "Log/")) ......

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();

}