看看我的代码错在哪里???
public void log(string str)
{
string Name = DateTime.Now.ToShortDateString();
string path = Server.MapPath("log/");
FileInfo fs = new FileInfo(path + Name + ".log"); if (!fs.Exists)
{
fs.CreateText();
} using (StreamWriter sw = fs.AppendText())
{
sw.WriteLine(str);
sw.Flush();
sw.Close();
sw.Dispose();
}
}
public void log(string str)
{
string Name = DateTime.Now.ToShortDateString();
string path = Server.MapPath("log/");
FileInfo fs = new FileInfo(path + Name + ".log"); if (!fs.Exists)
{
fs.CreateText();
} using (StreamWriter sw = fs.AppendText())
{
sw.WriteLine(str);
sw.Flush();
sw.Close();
sw.Dispose();
}
}
D:\WorkFlow\workFlow\log\2010-8-31.log”正由另一进程使用,因此该进程无法访问该文件。哪里没关??
using( FileInfo fs = new FileInfo(path + Name + ".log"))
{ if (!fs.Exists)
{
fs.CreateText();
} using (StreamWriter sw = fs.AppendText())//这一行,应该是从fs获取的stream吧。具体忘了
{
sw.WriteLine(str);
}
}
第二次就报 using (StreamWriter sw = fs.AppendText()) 这里的错了再点击多几次就好了··难道是 CreateText 还为释放???
{
StreamWriter sw = fs.CreateText();
sw.Close();
}
改为
using (StreamWriter sw = fs.CreateText())
{
}
{
FileStream fileCreat = fs.Create();
fileCreat.Close();
}