开发者

Monitoring a large log file in C#

I have to monitor a large log file during the day with C#. The size开发者_运维知识库 goes up to 200-300 MB for a day.

What is the most efficient way to analyze it?

The file is locked by the producing program. Preferably I would either have a read which realises that lines have been added or would read backwards.


A combination of MemoryMappedFile and FileSystemWatcher should do the trick.


You will never achieve good results with C#.

I created application in C++ and I used MFC String to search 1GB file.
It takes about 15-20 seconds. After that I used char type and it takes about 3 sec!!!!

C# has lot of overhead and if you need really fast solution, use C++ and TCHAR, char, data type.


Change log rotation to a smaller value and then process the rotated logs - or - Process the whole log file the first time and remember the fileoffset / line for the next checking interval.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜