开发者

StreamWriter stops writing when file is opened from web link

Following on from my previous question...

The following code creates log files on a web server:

private void LogMessage(Message msg)
{
    using (StreamWriter sw = File.AppendText(_logDirectory + DateTime.Now.ToString("yyyyMMddHH") + ".txt"))
    {
        sw.WriteLine(msg.ToString());
    }
}

The log files are linked to from an admin page on the web site:

foreach (FileInfo file in logDir.GetFiles())
{
    Response.Write("<a href='http:// .... /Logs/" + file.Name + "'>" + file.Name + "</a>");
}

I'm getting the problem that after someone looks at one of the log files from the link, that log file stops being w开发者_如何学JAVAritten to.


In addition to the try catch, did you try to:

  • Check for file == null
  • InitializeLifetimeService
  • AutoFlush
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜