March 26, 2011

Using a Connection String Name with Log4Net AdoNetAppender

Log4Net is a great tool to quickly add logging to a .Net application. However one feature that has been missing is the ability to provide a connection string name in the configuration for the AdoNetAppender. Currently out of the box you have to provide the full connection string in the AdoNetAppender configuration settings. This can violate the DRY principle if the same connection string is already set up in the connectionStrings section of the configuration.

So the question is: How can we enhance the Log4Net AdoNetAppender to have the ability to refer to an already existing connection string defined in the connectionStrings section of the configuration?