阅读文本文件动态C#的变化 [英] Read Changes on a text file dynamically c#

查看:126
本文介绍了阅读文本文件动态C#的变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,其日志写入持续到一个文本文件中。
我没有它的源代码,所以我不能对其进行修改以任何方式,它也与Themida保护。

I have a program that continuously writes its log to a text file. I don't have the source code of it, so I can not modify it in any way and it is also protected with Themida.

我需要读取日志文件并执行根据文件的内容,一些脚本。
,因为这是连续写入它的程序已锁定文件我无法删除该文件。
那么,什么将是更好的方式来读取文件和只读文件的新线路?
保存最后一行的位置?或者是有什么,这将是有益的在C#中解决它。

I need to read the log file and execute some scripts depending on the content of the file. I can not delete the file because the program that is continuously writing to it has locked the file. So what will be the better way to read the file and only read the new lines of the file? Saving the last line position? Or is there something that will be useful for solving it in C#?

推荐答案

也许使用的 FileSystemWatcher的与文件共享打开文件(因为它正在被另一个进程使用)一起。汉斯帕桑特提供了一个很好的答案对于这部分这里

Perhaps use the FileSystemWatcher along with opening the file with FileShare (as it is being used by another process). Hans Passant has provided a nice answer for this part here:

var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); 
        using (var sr = new StreamReader(fs)) {
            // etc...
        } 

有一个看这个的问题和接受的答案也可以帮助。

Have a look at this question and the accepted answer which may also help.

这篇关于阅读文本文件动态C#的变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆