StreamWriter stops writing when file is opened from web link

Posted by fearofawhackplanet on Stack Overflow See other posts from Stack Overflow or by fearofawhackplanet
Published on 2010-03-22T11:52:01Z Indexed on 2010/03/22 19:51 UTC
Read the original article Hit count: 282

Filed under:
|
|
|
|

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 written to.

© Stack Overflow or respective owner

Related posts about streamwriter

Related posts about filestream