views:

78

answers:

3

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?

A: 

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.

Jekke
+1  A: 

Just log your lines as XML (other formatting will work too of course).

This is how we do it:

<USERID>GUID</USERID><ERRORCODE>INVALID_XML</ERRORCODE><DESCRIPTION>File x is not in correct xml format</DESCRIPTION>

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.

Carra
+1  A: 

You might try using a different Appender (say, a DBAppender) (with an Error threshold, of course) and then sort the resulting tables.

McWafflestix