The problem you're having is that instead of specifing a
ConnectionString property in the config file, you're finding the
Appender and setting it in code Application_Start. When the config file
changes, log4net gets reinitialized but you're never resetting the
ConnectionString.
You need to either to extend AdoNetAppender:
/*
<appender name="MyAdoNetAppender"
type="Company.Logging.MyAdoNetAppender">
*/
public class MyAdoNetAppender : AdoNetAppender
{
protected string ConnectionString
{
get { return base.ConnectionString; }
set { base.ConnectionString =
ConfigurationSettings.AppSettings["Logger.ConnectionString"]; }
}
}
Or write your own PatternConverter:
<!-- log4net 1.2.9 beta -->
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<connectionString type="log4net.Util.PatternString">
<converter>
<name value="appSettings" />
<type value="Company.Logging.AppSettingsPatternConverter, Company"
/>
</converter>
<conversionPattern value="%appSettings{Logger.ConnectionString}" />
</connectionString>
...snip...
</appender>
PatternConverters are nice but they're not the most intuitive thing to
setup :-/
--- Jason Goldsmith <[EMAIL PROTECTED]> wrote:
> FINALLY...I have resolved my issue.
>
> For anyone who is interested, if you separate your log4net
> configurations into its own config file (ex. log4net.config), but you
> have your logger.ConnectionString set in the web.config file you
> can't
> change the log4net logging level settings. I attempted to follow a
> lot
> of the good suggestions and set the adoAppender in the
> Application_Start
> of the global.asax file, but unfortunately this did not work for me.
> Now, I don't know if this is the recommended solution, nor the
> correct
> solution, but it works and at this point that is my major concern.
> If
> anyone knows if there is a better way, please let me know.
>
>
> Thanks for all the assistance,
>
>
> Jason Goldsmith
>
> -----Original Message-----
> From: Jason Goldsmith [mailto:[EMAIL PROTECTED]
> Sent: Monday, August 22, 2005 1:25 PM
> To: Log4NET User
> Subject: RE: Cannot switch between logging levels
>
> Ok...I'm still having problems with switching between logging level
> using the ADONetAppender. I have implemented the Internal Debugging
> and
> whenever I switch I receive the following message:
>
> log4net:ERROR [ADONetAppender] Could not open database connection []
> System.InvalidOperationException: The ConnectionString property has
> not
> been initialized.
> at System.Data.SqlClient.SqlConnection.Open()
> at log4net.Appender.ADONetAppender.InitializeDatabaseConnection()
> log4net: DOMConfigurator: Created Appender [AdoNetAppender]
>
>
> Any Ideas?