Sorry for using the Forums for this purpose, but while testing - noticed that copytruncate will not truncate a file in use.
When this happens, you get following stack trace
C:>logrotate.exe -f "logrotate.conf"
logrotate: Force option set to true
logrotate: Error truncating file D:\BMCSoftware\BMCARSystem\Arserver\Db\arerror.log
logrotate: Exception: The process cannot access the file 'D:\BMCSoftware\BMCARSystem\Arserver\Db\arerror.log' because it is being used by another process.
logrotate: StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, St
ring msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)
Solution is simple and elegant (change to program.cs - line 836)
Instead of doing this - where the ctor will fail
FileStream fs = new FileStream(fi.FullName, FileMode.Open);
fs.SetLength(0);
fs.Close();
Change the FileShare to ReadWrite :
FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
fs.SetLength(0);
fs.Close();
Cheers,
-- Geert
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry for using the Forums for this purpose, but while testing - noticed that copytruncate will not truncate a file in use.
When this happens, you get following stack trace
C:>logrotate.exe -f "logrotate.conf"
logrotate: Force option set to true
logrotate: Error truncating file D:\BMCSoftware\BMCARSystem\Arserver\Db\arerror.log
logrotate: Exception: The process cannot access the file 'D:\BMCSoftware\BMCARSystem\Arserver\Db\arerror.log' because it is being used by another process.
logrotate: StackTrace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, St
ring msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at logrotate.Program.RotateFile(logrotateconf lrc, FileInfo fi)
Solution is simple and elegant (change to program.cs - line 836)
Instead of doing this - where the ctor will fail
Change the FileShare to ReadWrite :
Cheers,
-- Geert
Thanks for this...will include this fix in next update.