Georg Jansen posted on September 27, 2005 13:06
Log4Net gives us a collection of log appenders making it possible to choose where we writs logs. One of the possible appenders is the AdoNetAppender which write log-rows to a database.
Why log to database?
- A database is “by nature” constructed to store and retrieve structured data.
- Database gives us rich query possibilities; people acquainted with the power of Sql Select statements will know the flexibility of the extraction possibilities at their fingertips.
- Database, are in most environments, a part of the daily maintenance, i.e. backup routines exists.
- Several tools are available for creating ad hoc reports from a database
- Need for log rotation goes away, as you can delete records from the database once they are no longer useful, or move them to separate history tables.
- Environments with clusters of web servers (for high availability) will benefit - all web servers can log to a single database. This obviates the need to collate many separate logfiles.
- Database are usually centralized, logs don’t get stored on several PC’s.
- Enables output of log events from Stored Procedures to the same log.
From my point of view, one of the best features of Log4Net is the possibility to configure in runtime the log levels and the log targets (appenders). Logging to database may not be the only solution in all environments. Personally I prefer to use logging to database in combination with a RollingFileAppender – to keep track of the last logging events in case the database is unavailable.