views:

26

answers:

2

A co-worker had told me that he thought it was possible to store/access log4net's config file in a database rather than a standard config file. If it's possible, how would you go about doing this? Google search seems to be failing me.

+1  A: 

You can create your log4net configuration through the code itself (see the log4net configuration section for details and a brief example). It is just more convenient to have a settings file available.

It depends on what you need to accomplish. If you're looking for something that is the equivalent of a configuration file sitting in a row in the database, you're probably out of luck.

However, if you created your own custom settings table in your application, and then dynamically created the logger with those settings, you should be all set.

Dillie-O
+2  A: 

You could store the configuration xml file in a database row and feed this as XmlElement to the XmlConfigurator.Configure(); method. This is pretty straight-forward and you do not loose any configuration features that log4net offers. Two things to consider:

  • How do you want to deal with problems reading the config from the database? (fail over configuration in a file?)
  • How would your application pick up configuration changes? Maybe it is good enough that this happens on re-start of the application but then again it may not.
Stefan Egli