I want to use Log4NET to log into my DB and following some tutorials I see that I have to configure a connection string for the DAO appender.
I already have a connection string in my web.config for DB connection so I’m wondering if I can reference that instead of setting a new one.
I usually change my connection string to switch from dev DB to production DB so it could be very useful to share the same connection parameters.
Edit: since this was posted, log4net now supports specifying the connection string name in the config. From https://issues.apache.org/jira/browse/LOG4NET-88 –
There’s an example in this answer.
If you don’t have the connection string defined in the
<ConnectionStrings>section then you can set the connection string at runtime using this class:You invoke
SetConnectionStringwith the connection string just after you’ve configured log4net.However, there are a couple of things I would note:
Log4net database appenders don’t like being created without a connection string, and throw an (internal) error – and during unit testing, I’ve seen tests take more than 10 seconds when given a fake connection string.