如何监视文件以进行更改 [英] How To Monitor A File For Changes
问题描述
您好,
我要做的是监控一个日志文件以获取要写入的特定文本行
。一旦写完文本,我想从
解析观察文本的实例,直到它到达指定文本的另一行
。我知道我可以使用FileSystemWatcher类来查看更改日志文件时的
,我只是无法弄清楚如何检索
后面附加了什么文本自上次更改以来的日志文件。这个
日志文件非常*非常活跃,并且基本上会有文字写入
。我需要在每次出现写入日志文件的
观看文本行时触发我的解析器,即使它每天写了数百次b
$ b 。
任何人对我如何做这个有任何建议或联系吗?
谢谢!
Hello,
What I''m trying to do is monitor a log file for a certain line of text
to be written to it. Once that text is written, I want to parse from
that instance of the watched text until it reaches another line of
specified text. I know I can use the FileSystemWatcher class to see
when the log file is changed, I just can''t figure out how to retrieve
what text was appended to the log file since the previous change. This
log file is *very* active and would basically have text written to it
constantly. I need to trigger my parser on every occurrence of the
watched line of text being written to the log file, even if it''s written
hundreds of times a day.
Anyone have any suggestions or links on how I might go about doing this?
Thanks!
推荐答案
MarcJ< ma *** @ certifichecks.com> scripsit:
MarcJ <ma***@certifichecks.com> scripsit:
我正在尝试做的是监视日志文件以查找要写入的特定文本行。写完文本后,我想从
中查看已观看文本的实例,直到它到达指定文本的另一行。我知道我可以使用FileSystemWatcher类来查看更改日志文件的时间,我只是无法弄清楚如何检索自上次更改以来附加到日志文件的文本。这个
日志文件非常活跃,并且基本上会不时地写入文本。我需要在每次看到正在写入日志文件的文本行中触发我的解析器,即使它每天写了数百次。
What I''m trying to do is monitor a log file for a certain line of text
to be written to it. Once that text is written, I want to parse from
that instance of the watched text until it reaches another line of
specified text. I know I can use the FileSystemWatcher class to see
when the log file is changed, I just can''t figure out how to retrieve
what text was appended to the log file since the previous change. This
log file is *very* active and would basically have text written to it
constantly. I need to trigger my parser on every occurrence of the
watched line of text being written to the log file, even if it''s written
hundreds of times a day.
>
为什么每次收到通知时都不会读取文件的内容
内容已更改并将其与文件的先前版本进行比较?
-
Herfried K. Wagner
MVP·VB Classic,VB.NET
< http: //www.mvps.org/dotnet>
Why not read the contents of the file every time you get a notification
that the content changed and compare it to the previous version of the file?
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
文章< bm ************ @ ID-208219.news.uni -berlin.de>,hirf-spam-me-
he**@gmx.at 说...
In article <bm************@ID-208219.news.uni-berlin.de>, hirf-spam-me-
he**@gmx.at says...
MarcJ< ma *** @ certifichecks.com> scripsit:
MarcJ <ma***@certifichecks.com> scripsit:
我正在尝试做的是监视日志文件以查找要写入的特定文本行。写完文本后,我想从
中查看已观看文本的实例,直到它到达指定文本的另一行。我知道我可以使用FileSystemWatcher类来查看更改日志文件的时间,我只是无法弄清楚如何检索自上次更改以来附加到日志文件的文本。这个
日志文件非常活跃,并且基本上会不时地写入文本。我需要在每次看到正在写入日志文件的文本行中触发我的解析器,即使它每天写了数百次。
What I''m trying to do is monitor a log file for a certain line of text
to be written to it. Once that text is written, I want to parse from
that instance of the watched text until it reaches another line of
specified text. I know I can use the FileSystemWatcher class to see
when the log file is changed, I just can''t figure out how to retrieve
what text was appended to the log file since the previous change. This
log file is *very* active and would basically have text written to it
constantly. I need to trigger my parser on every occurrence of the
watched line of text being written to the log file, even if it''s written
hundreds of times a day.
>
为什么每次收到通知时都不会读取文件内容?内容已经更改并将其与文件的先前版本进行比较?
Why not read the contents of the file every time you get a notification
that the content changed and compare it to the previous version of the file?
这个日志文件可能大约是200MB。在实时情况下,
我不认为我可以使用该方法而不会对性能产生巨大影响
考虑到文件被写入多次第二。
This log file would probably be around 200MB. In a real-time situation,
I don''t think I can use that method without a HUGE hit to performance
considering the file is being written to several times a second.
MarcJ< ma *** @ certifichecks.com> scripsit:
MarcJ <ma***@certifichecks.com> scripsit:
我要做的是监控日志文件以获取某一行文本
写到它。写完文本后,我想从
中查看已观看文本的实例,直到它到达指定文本的另一行。我知道我可以使用FileSystemWatcher类来查看更改日志文件的时间,我只是无法弄清楚如何检索自上次更改以来附加到日志文件的文本。这个
日志文件非常活跃,并且基本上会不时地写入文本。我需要在每次看到正在写入日志文件的文本行中触发我的解析器,即使它每天写了数百次。
What I''m trying to do is monitor a log file for a certain line of text
to be written to it. Once that text is written, I want to parse from
that instance of the watched text until it reaches another line of
specified text. I know I can use the FileSystemWatcher class to see
when the log file is changed, I just can''t figure out how to retrieve
what text was appended to the log file since the previous change. This
log file is *very* active and would basically have text written to it
constantly. I need to trigger my parser on every occurrence of the
watched line of text being written to the log file, even if it''s written
hundreds of times a day.
>
为什么每次收到通知时都不会读取文件内容?内容已经更改并将其与文件的先前版本进行比较?
Why not read the contents of the file every time you get a notification
that the content changed and compare it to the previous version of the file?
此日志文件可能大约为200MB。在实时情况下,我不认为我可以使用该方法而不会对性能产生巨大影响
考虑到文件每秒写入几次。
This log file would probably be around 200MB. In a real-time situation,
I don''t think I can use that method without a HUGE hit to performance
considering the file is being written to several times a second.
stream类提供了一个''Seek''方法。你可以在操作之前保存长度
,然后打开文件,寻找位置和
只读取此位置后的文字。
>
-
Herfried K. Wagner
MVP·VB Classic,VB.NET
< http:// www .mvps.org / dotnet>
The stream class provides a ''Seek'' method. You can save the length
before the manipulation, then open the file, seek to the position and
read only the text after this position.
--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>
这篇关于如何监视文件以进行更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!