日期:2014-05-18 浏览次数:20899 次
StreamWriter sw = new StreamWriter(文件路径, true); sw.Write(string类型的值); sw.Dispose();
------解决方案--------------------
上面的改下
sw.WriteLine(); sw.Write(string类型的值);
------解决方案--------------------
public void WriteLog(string conten)
{
try
{
//判断文件夹是否存在
if (!this.CreateDirectoy())
{
//如果不存在,停止
return;
}
//获取文件的名称,每天生成一个日志文件
this.FixedLogFileName = DateTime.Now.ToString("yyyy-MM-dd") + this.FixedLogFileName;
string content =DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+"\t"+conten +Environment.NewLine;
File.AppendAllText(this.LogDirName + "\\" + this.FixedLogFileName, content);
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
}
------解决方案--------------------
FileStream fs=new FileStream("xxxx",FileMode.Append,FileAccess.Write);
StreamWriter sw=new StramWriter(fs,Encoding.ASCII);
sw.WriteLine(strData);