Parse log files programmatically in .NET

冷暖自知 提交于 2019-12-04 20:55:32

You could use Microsoft's Log Parser (Download here). The tool also exposes a COM interface that will let you access the results programmatically. This blog post has a small (partial) instructions for doing that with version 2.1.

So now instead of feeling it is reinventing the wheel, you probably feel like it is over-engineered. ;)

We ended up simply outputting XML as our log format and it became trivial to parse.

This looks like a typical case of .NET regular expressions

This way you can search for patterns like "User entered term: ". You can extract the group match afterwards

can log4net not read it's own format patterns? Once it reads the format back in, can't you then parse just the %message% section?

A better question maybe why you don't just write that search term to a database at the same time you make the log call or have another log file through log4net that just logs the %message% and all you write to that log is the search term? I really don't think you want to be parsing logs if you can avoid it...at least going forward.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!