diff --git a/src/main/Log4D.pas b/src/main/Log4D.pas index 478e71b..a69abae 100644 --- a/src/main/Log4D.pas +++ b/src/main/Log4D.pas @@ -3042,7 +3042,6 @@ constructor TLogFileAppender.Create(const Name, FileName: string; procedure TLogFileAppender.SetLogFile(const Name: string); var strPath: string; - f : TextFile; begin CloseLogFile; FFileName := Name; @@ -3057,20 +3056,14 @@ procedure TLogFileAppender.SetLogFile(const Name: string); begin // Check if directory exists strPath := ExtractFileDir(FFileName); - if (strPath <> '') and not DirectoryExists(strPath) then + if (strPath <> '') and not DirectoryExists(strPath) then ForceDirectories(strPath); //FIX 04.10.2006 MHoenemann: // SysUtils.FileCreate() ignores any sharing option (like our fmShareDenyWrite), - // Creating new file - AssignFile(f, FFileName); - try - ReWrite(f); - finally - CloseFile(f); - end; - // now use this file - FStream := TFileStream.Create(FFileName, fmOpenReadWrite or fmShareDenyNone); + // Creating new file directly via TFileStream with fmCreate, which truncates/creates + // the file and gives us the stream with the desired share mode in one step. + FStream := TFileStream.Create(FFileName, fmCreate or fmShareDenyNone); end; WriteHeader; end;