按相似性对 log4net 错误进行分组
我们使用 log4net 来记录各种 Web 应用程序的应用程序异常。 目前,我们使用阈值为 Info
的 RollingLogFileAppender
和阈值为 Warn
的 SmtpAppender
。
问题是我们没有简单的方法来按内容对错误日志条目进行分组。 有些错误是我们经常看到的,而另一些错误则时不时出现。 我们希望能够自动跟踪相同错误的发生。
从概念上讲,这很简单 - 对日志条目的最后(例如 50 个)字符进行模式匹配应该允许我们执行此操作。
有没有人实施过这样的解决方案,或者有人可以推荐更好的方法吗?
We use log4net for logging application exceptions for a variety of web applications. At present we use the RollingLogFileAppender
with a threshold of Info
and SmtpAppender
with a threshold of Warn
.
The problem is that we have no easy way of grouping error log entries by their contents. There are certain errors that we see frequently, and others that come up now and then. We want to be able to automatically track occurrences of the same error.
Conceptually this is simple - a pattern match on the last, say, 50 characters of the log entry should allow us to do this.
Has anyone implemented such a solution, or can anyone recommend a better approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以尝试使用不同的 Appender(例如 DBAppender)(当然有错误阈值),然后对结果表进行排序。
You might try using a different Appender (say, a DBAppender) (with an Error threshold, of course) and then sort the resulting tables.
只需将您的行记录为 XML(当然其他格式也可以)。
我们是这样做的:
然后我们解析日志文件并在 datagridview 中显示它们,其中包含错误代码、描述、日志级别列。 然后我们可以快速排序或过滤,例如错误代码。
在数据集中查找那些 INVALID_XML 条目将快速向我们显示这些错误是否存在于日志文件中。
通过 userIds,我们还可以看到客户端在登录期间进行的所有调用。
Just log your lines as XML (other formatting will work too of course).
This is how we do it:
Then we parse the log files and show them in a datagridview with a column for errorcode, description, loglevel. We can then quickly sort or filter by, for example ERRORCODE.
Looking in the dataset for those INVALID_XML entries will quickly show us if these errors were present in the logfile.
And with the userIds we can also see all the calls that a client did during their login time.
我认为这样的解决方案不存在。 但是,您可以定义自定义日志级别(或选择未使用的日志级别之一)以输出到其自己的 ILog 以获取更常见的错误,并在“主”错误日志中过滤掉它们,而无需太多麻烦。
I don't think such a solution exists out of the box. However, you can define a custom log level (or pick one of the unused ones) to output to its own ILog for the more common errors and filter them out on the "main" error log without too much trouble.