Windows 使用Powershell分析另一个应用程序正在使用的日志文件

Windows 使用Powershell分析另一个应用程序正在使用的日志文件,windows,parsing,powershell,windows-server-2012,Windows,Parsing,Powershell,Windows Server 2012,我有两个日志文件(.txt),它们是从一个应用程序生成的,该应用程序每秒添加一行新的文本,如下所示: 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 我的问题是,我无法使用Get Content访问该文件,因为它会引发IO.Exception错误。我无法结束应用程序,因为它正在监视,无法停止。我还应该提到,该应用程序还每隔10分钟写入

我有两个日志文件(.txt),它们是从一个应用程序生成的,该应用程序每秒添加一行新的文本,如下所示:

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
我的问题是,我无法使用Get Content访问该文件,因为它会引发IO.Exception错误。我无法结束应用程序,因为它正在监视,无法停止。我还应该提到,该应用程序还每隔10分钟写入另一个日志文件,但我可以很好地解析该日志文件。我甚至可以在记事本中打开活动的10分钟日志文件,没有任何问题。我猜另一个日志每秒钟更新一次,它就锁定了文件

以下是我对1秒日志文件的解析代码:

$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 }
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.
以下是我在尝试分析活动1秒日志文件时收到的错误:

$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 }
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.

我们将衷心感谢您的帮助

如果文件在读写过程中经常被永久锁定,恐怕这是不可能的,访问它的唯一方法就是停止使用它的进程。

你能在记事本中打开“锁定”的文件吗?你能把它复制到另一个地方,然后继续复制吗?不幸的是,我既不能打开也不能复制文件;不知道从那里去哪里。是问题的c#解决方案;他们使用PowerShell也可以访问的.NET库。标准免责声明:不要在生产监控系统上进行测试。祝你好运