views:

51

answers:

1

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.

A: 

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

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