日志文件监视器 [英] Log File Monitor

查看:286
本文介绍了日志文件监视器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以打开一个文本文件并读取内容,而另一个应用程序正在更新该文件,使其不会导致锁冲突?

Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict?

我需要从一个应用程序监视日志文件,每次事件发生时由另一个应用程序更新。

I need to monitor a log file from one application which is updated by another application each time an event occurs.

我在检查文件是否正在使用中,但是在所有情况下似乎都不起作用。

I do check if the file is in use before I try to read it, but that does not seem to work in all cases.

谢谢Pieter

推荐答案

这取决于第一个应用程序如何打开该文件。

it depends on how the first app open that file.

ie when调用CreateFile API来打开一个文件,有dwShareMode参数告诉api如何打开它(如果这被赋予0,它不能从其他应用程序IIRC访问)。
否则从该文件读取应该没有问题。
如果没有错误,检查是否该文件正在打开只读你可以调用

i.e when calling CreateFile API to open a file, there is dwShareMode param which tells the api how to open it (if this was given 0, it can't be accessed from other applications IIRC). otherwise there should be no problem with reading from that file. if im not mistaken, to check if that file is being opened read only u can call something like

CreateFile(pchar(fName), GENERIC_READ or GENERIC_WRITE, 0, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0) ;

这篇关于日志文件监视器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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