开发者

StreamWriter stops writing when file is opened from web link

开发者 https://www.devze.com 2022-12-23 13:43 出处:网络
Following on from my previous question... The following code creates log files on a web server: private void LogMessage(Message msg)

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

精彩评论

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

关注公众号