I have a couple of log files (.txt) that are generated from an application that add new lines of text like these every second:
2/20/2016 1:22:47 PM 67.8
2/20/2016 1:22:48 PM 67.8
2/20/2016 1:22:49 PM 67.7
2/20/2016 1:22:50 PM 67.6
My problem is that I cannot access the file using Get-Content because it throws an IO.Exception error. I cannot end the application because it is monitoring and cannot be stopped. I should also mention that the app also writes to another log file every 10 minutes but I can parse that log file perfectly fine. I can even open the active 10 minute log file in Notepad with no issues. I'm guessing with the other log updating every second it has a lock on the file.
Here is my parsing code for the 1 second log file:
$Log = Get-ChildItem -Path 'C:\Users\Public\App' | Where-Object {$_.Name -match "LOG"} | Sort LastWriteTime | Select -Last 1
$Number = Get-Content -Path "C:\Users\Public\App\$Log" -Tail 1 | Select-String -Pattern $regexSPL -AllMatches | % { $_.Matches } | % { $_.Groups }
Here is the error I receive when trying to parse the active 1 second log file:
Get-Content : The process cannot access the file 'C:\Users\Public\App\LOG_3_18_2016_12.26.30 AM.txt'
because it is being used by another process.
Any help will be sincerely appreciated.