我正在使用以下代码写入文本文件。我的问题是,每次执行以下代码时,它都会清空 txt 文件并创建一个新文件。有没有办法追加到这个txt文件?
string[] lines = {DateTime.Now.Date.ToShortDateString(),DateTime.Now.TimeOfDay.ToString(), message, type, module };
System.IO.File.WriteAllLines(HttpContext.Current.Server.MapPath("~/logger.txt"), lines);
最佳答案
File.AppendAllLines
应该可以帮助您:
string[] lines = {DateTime.Now.Date.ToShortDateString(),DateTime.Now.TimeOfDay.ToString(), message, type, module };
System.IO.File.AppendAllLines(HttpContext.Current.Server.MapPath("~/logger.txt"), lines);
关于c# - 使用 WriteAllLines 追加到文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15379136/