3

We need a solution to do database logging with specifically version 2.0.3 of log4net. Because this is an older version of log4net, I would like to know how to approach the issue of getting this version to play nicely with sql server 2012.

  1. After going through this tutorial, I'd like to know whether it is necessary to use nhibernate to do this?
  2. For 2.0.3, are there any other dependencies that would be necessary to do database logging?
Alex Gordon
  • 57,446
  • 287
  • 670
  • 1,062
  • it's usually not considered a good idea to log to a database - better to store it in the local filesystem to reduce the number of possible points of failure. Error logging is the most basic form of error handling and should be as simple and foolproof as possible. – user1666620 Jan 15 '16 at 16:13
  • @user1666620 so when you have say 10 or more servers, which log do you look at? – stuartd Jan 15 '16 at 16:56
  • @stuartd tbh I think Jon Skeet put it best here http://stackoverflow.com/questions/290304/is-writing-server-log-files-to-a-database-a-good-idea - write locally first, with batch jobs to insert the logs to a central database during periods of low activity. After all, what happens if the network suffers a hiccup during an event which is being written to the logging db? – user1666620 Jan 15 '16 at 16:58
  • @stuartd the write can be done every few minutes as well - it's up to you to choose the right schedule. – user1666620 Jan 15 '16 at 17:01
  • @user1666620 for 90%+ of systems, writing to the database is just fine, though I would always recommend writing to a file as well. The AdoNetAppender buffers inserts by default, and of course you can use [an asynchronous appender](https://github.com/cjbhaines/Log4Net.Async). – stuartd Jan 15 '16 at 17:09

2 Answers2

1

No... NHibernate is overkill and would slow down your logging. You want logging to be fast. With log4net you should be able to directly log into a database table. No need to put an ORM between it.

As your specification of SQL 2012, you do not need any other assemblies besides the .NET framework and log4net.

NB the log4net documentation has an example of the needed configuration and table schema: https://logging.apache.org/log4net/release/config-examples.html

Niels V
  • 1,005
  • 8
  • 11
1

You can use the AdoNetAppender which already comes with log4net. You do not need anything else. You can refer to THIS tutorial on how to implement it.

You also need to remember that log4net appenders are synchronous some operate on a batch of log events to improve performance however they all block the calling thread if too many log events are generated so I also highly recommend using an asynchronous forwarder. A very good implementation is explained HERE.

MaYaN
  • 6,683
  • 12
  • 57
  • 109