标签:
string fname = Directory.GetCurrentDirectory() + "\\LogFile.log";
FileInfo finfo = new FileInfo(fname);
if (!finfo.Exists)
{
FileStream fs;
fs = File.Create(fname);
fs.Close();
finfo = new FileInfo(fname);
}
if (finfo.Length > 1024 * 1024 * 10)
{
/**/
///文件超过10MB则重命名
File.Move(Directory.GetCurrentDirectory() + "\\LogFile.log", Directory.GetCurrentDirectory() + DateTime.Now.TimeOfDay + "\\LogFile.log");
/**/
///删除该文件
//finfo.Delete();
}
using (FileStream fs = finfo.OpenWrite())
{
/**/
///根据上面创建的文件流创建写数据流
StreamWriter w = new StreamWriter(fs);
w.BaseStream.Seek(0, SeekOrigin.End);
w.Write("{0} {1} \n\r", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString());
var sele = db.NikeDTCDailyReport.Where(p => true).ToList();
foreach (var item in sele)
{
w.WriteLine(item);
}
w.WriteLine(sele);
w.Flush();
w.Close();
}
标签:
原文地址:http://www.cnblogs.com/xiaojian1/p/5467620.html