#48 Log file locked by FileAppender

v1.2.0
open-fixed
General (51)
5
2003-09-18
2003-09-03
No

The appender locks exclusively the file by default.
I've fixed it with the following code to its OpenFile
method:

virtual protected void OpenFile(string fileName, bool
append)
{
lock(this)
{
Reset();

LogLog.Debug("FileAppender: Opening file for writing
["+fileName+"] append ["+append+"]");

// Ensure that the directory structure exists
Directory.CreateDirectory((new
FileInfo(fileName)).DirectoryName);

FileMode mode = FileMode.Create;
if (append) mode = FileMode.Append;

SetQWForFiles(new StreamWriter(
new FileStream(fileName, mode, FileAccess.Write,
FileShare.Read), m_encoding));

m_fileName = fileName;
m_appendToFile = append;

WriteHeader();
}
}

The change is about passing an specifically constructed
FileStream to StreamWriter, so we can specify the
FileShare.Read mode.

Discussion

  • Nicko Cadell

    Nicko Cadell - 2003-09-18
    • status: open --> open-fixed
     
  • Nicko Cadell

    Nicko Cadell - 2003-09-18

    Logged In: YES
    user_id=278872

    Thanks, will be available in the next release.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks