开发者

Monitoring a large log file in C#

开发者 https://www.devze.com 2023-01-07 19:39 出处:网络
I have to monitor a large log file during the day with C#. The size开发者_运维知识库 goes up to 200-300 MB for a day.

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

精彩评论

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