Most efficient way to tail a rolling log file in Windows

14,552

Solution 1

You can use below Powershell command:

get-content {file_name} -tail 10 -wait

Solution 2

I would do that in a loop.

while($true) { if( Test-Path .\file.log ) { Get-Content .\file.log -Wait -Tail 1 -ErrorAction SilentlyContinue} }
Share:
14,552
Senri
Author by

Senri

Updated on June 26, 2022

Comments

  • Senri
    Senri almost 2 years

    What is the most efficient way to tail log files that are rolled over when they get to a certain size. Some app log files can get quite large, 100+ MB.

    For example: Tailing "file.log".

    After it gets to 25MB, that file is renamed ("file.log.1"). A new blank fresh "file.log" is created to replace it.

    One option I found is: PowerShell cmdlet Get-Content

    gc file.log -wait -tail 1
    

    Anyone know if it is smart enough to know that a file has rolled over (re-named, re-created) as such no line is missed during the roll over?

    Or if some checks are needed. If so can I get some ideas please.

    Any better options for Windows?

    Thanks.