snaketail-net icon indicating copy to clipboard operation
snaketail-net copied to clipboard

snaketail causing certain lock on text file preventing continuation of log file - not read only

Open jwroosch opened this issue 6 years ago • 4 comments
trafficstars

Reporting this just in case someone else experiencing something similar strange behavior, possibly involving snaketail. We're having 2 environments here: A:

  • the log file is in a folder with underscore(s) in the folder name
  • the program files developed in Visual Studio 2010 and C B:
  • the log file is in a folder with dots(s) in the folder name
  • the program files developed in Visual Studio 2017 and C#

In environment A: all works fine In environment B: when viewing the log file in snaketail, the log file stops working as if locked. But the file still can be deleted, so not a real lock but to a certain degree, preventing the program from adding anymore lines to the log file. When closing the view, the log starts functioning again, new lines being added as expected. What could cause this, the dot(s) in the folder name, or .. Could it be reproduced? Could it be solved? (So snaketail only monitors files in a read only manner) Cheers.

jwroosch avatar Jul 15 '19 14:07 jwroosch

Pull-Requests are welcome to make the file-monitor even better.

Version 1.9.6 have been released, that introduces the keyboard shortcut CTRL + R

snakefoot avatar Oct 11 '19 19:10 snakefoot

Hi, thanks for the heads up, i tested it with 1.9.6 but regarding this issue seems unchanged. So unfortunately not solved (yet). Best regards

jwroosch avatar Oct 21 '19 09:10 jwroosch

Like I just wrote. Pull Request are welcome

snakefoot avatar Oct 21 '19 11:10 snakefoot

I was not able to fix this, but for anyone looking: I think there are more kinds of shareable file locks in Windows than covered under the docs at https://docs.microsoft.com/en-us/dotnet/api/system.io.fileshare?view=netcore-3.1

The file access is happening in snaketail-net\SnakeTail\LogFileStream.cs > LoadFile(...) line 317:

_fileStream = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete, 65536, FileOptions.SequentialScan);

The FileShare specified is correct. However, PowerShell's Set-Content will complain with:

Set-Content : The process cannot access the file ... because it is being used by another process.

when I call it like: Set-Content 'path\to\file.log' -Value $null so I replaced that with $null | out-file "path\to\file.log" instead.

However, I cannot always use out-file because a different program writes log files that out-file (and Sublime Text) cannot overwrite, but that Set-Content can.

It is strange but I have to mix both Set-Content and out-file to clear out log files. Thought I would point this out in case somebody accuses this issue of not being reproducible. The Windows flags do not work as documented!

ColinNg avatar Jun 18 '20 05:06 ColinNg