解析.NET编程的日志文件 [英] Parse log files programmatically in .NET

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

问题描述

我们有大量的(阅读:50000),使用log4net的创建我们的客户端应用程序比较小的(在500K读取,一般在50K)日志文件。典型的日志是这样的:

We have a large number (read: 50,000) of relatively small (read under 500K, typically under 50K) log files created using log4net from our client application. A typical log looks like:

Start Painless log
Framework:8.1.7.0
Application:8.1.7.0
2010-05-05 19:26:07,678 [Login ] INFO  Application.App.OnShowLoginMessage(194) - Validating Credentials...
2010-05-05 19:26:08,686 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Checking for Application Updates...
2010-05-05 19:26:08,830 [1     ] INFO  Framework.Globals.InstanceStartup(132) - Application Startup
2010-05-05 19:26:09,293 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Purchase History Data>:True
2010-05-05 19:26:09,293 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Shopping Assistant>:True
2010-05-05 19:26:09,294 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Shopping List>:True
2010-05-05 19:26:09,294 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Teeth>:True
2010-05-05 19:26:09,294 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Scanner>:True
2010-05-05 19:26:09,294 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Value Comparison>:True
2010-05-05 19:26:09,294 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Lotus Notes CRM>:True
2010-05-05 19:26:09,295 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Salesforce.com>:False
2010-05-05 19:26:09,295 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Lotus Notes Mail>:True
2010-05-05 19:26:09,295 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Sales Leads>:True
2010-05-05 19:26:09,295 [1     ] INFO  Framework.PluginManager.LogPluginState(150) - Plugin <Configurator>:True
2010-05-05 19:26:09,297 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Validating Database...
2010-05-05 19:26:10,342 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Validating Database...
2010-05-05 19:26:10,489 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Global Handlers...
2010-05-05 19:26:10,495 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Starting Main Window...
2010-05-05 19:26:10,496 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Initializing Components...
2010-05-05 19:26:11,145 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Restoring Location...
2010-05-05 19:26:11,164 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Plug Ins...
2010-05-05 19:26:11,169 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Panels...Order Manager
2010-05-05 19:26:11,181 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Orders...
2010-05-05 19:26:11,274 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Done Loading 1 Order
2010-05-05 19:26:11,314 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Panels...All Products
2010-05-05 19:26:11,471 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Purchase History Data
2010-05-05 19:26:11,545 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Shopping List
2010-05-05 19:26:11,597 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Teeth
2010-05-05 19:26:11,768 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Scanner
2010-05-05 19:26:11,810 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Value Comparison
2010-05-05 19:26:11,840 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...Sales Leads
2010-05-05 19:26:11,922 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Tabbed Areas...(Done!)
2010-05-05 19:26:11,923 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Adding Handlers...
2010-05-05 19:26:11,925 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Main Window Handlers...
2010-05-05 19:26:11,932 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Loading Main Menu...
2010-05-05 19:26:11,949 [1     ] INFO  Application.App.OnShowLoginMessage(194) - Initialization Complete.
2010-05-05 19:26:13,662 [1     ] INFO  Framework.ProductSearch.Search(342) - User entered term: <>

我希望能够分析这些日志服务器端(或者当他们上载或夜间),用于提取异常(它总是记录在错误或致命的)或其他特定的日志信息,如:

I'd like to be able to to parse these logs server side (either when they're uploaded or nightly) to extract either exceptions (which always log at ERROR or FATAL) or other specific log messages like:

2010-05-05 20:05:24,951 [1     ] INFO  Framework.ProductSearch.Search(342) - User entered term: <kavo>

要获得卡瓦一词,所以我们可以找出哪些人的真的搜索。

to get the 'kavo' term so we can find out what people are really searching for.

我试着解析(使用String.Split()和类似的方法),用手工的文字,但它真的感觉就像我重新发明轮子。

I've tried parsing the text by hand (using String.Split() and similar methods) but it really feels like I'm reinventing the wheel.

有一个很好的图书馆做这样的日志中提取?

Is there a nice library to do this kind of log extracting?

推荐答案

最后我们简单地输出XML作为我们的日志格式,它变得微不足道的解析。

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

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

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