Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging file locked by nreco #65

Closed
Demsei opened this issue May 2, 2024 · 5 comments
Closed

Logging file locked by nreco #65

Demsei opened this issue May 2, 2024 · 5 comments
Labels

Comments

@Demsei
Copy link

Demsei commented May 2, 2024

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

@VitaliyMF
Copy link
Contributor

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'.

@Demsei
Copy link
Author

Demsei commented May 2, 2024

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

@Demsei
Copy link
Author

Demsei commented May 3, 2024

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 ?

@VitaliyMF
Copy link
Contributor

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).

@Demsei
Copy link
Author

Demsei commented May 3, 2024

bingo! that's it !!
You are me todays HERO
thx

@Demsei Demsei closed this as completed May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants