Closed Demsei closed 3 months ago
How do you copy log files? You should be able to copy 'active' log file (that is currently in use by the app) if it is opened for 'read'. I tested that both on Windows and Linux.
Take a look at line 219 here where a file logger creates a FileStream
:
LogFileStream = new FileStream(LogFileName, FileMode.OpenOrCreate, FileAccess.Write);
FileShare
is not specified but by default it is FileShare.Read
which allows other processes to open the file for 'read'.
We are zipping with cabinet.dll from MS. The developer checks how the logging file is opened exactly. I will post the result here. thx
Hi, I can copy active file in explorer as you mentioned. We try to open the active logfile in cabinet callback fnFileOpen with CreateFileA(fileName, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUE_READONLY, nullptr). The result is INVALID_FILE_HANDLE and a call to GetLastError givs us rc=32 (ERROR_SHARING_VIOLATION). What can we do else ?
Have you tried to specify FILE_SHARE_READ|FILE_SHARE_WRITE ? It's not obvious but this sharing mode is less restrictive than just FILE_SHARE_READ (which does NOT allow other processes to write into the file, therefore you get ERROR_SHARING_VIOLATION).
bingo! that's it !! You are me todays HERO thx
Hi, we want to collect all logging files and zip them. If the logging process is running, the logging file is locked so another process is not able to zip it. That can we do? Stopping the process is not so good. thx