Well, I have looked at test cases and haven't found what I am trying to
do. In fact I simply would like to know if you have ever considered
adopting the .Net 2.0 ConfigurationSection system as for the moment
log4net only use the IConfigurationSectionHandler. In a number of
situations the ConfigurationSection would be more convenient. Here are 2
use cases where I could have advantage of it:
- application specific log file:
We are developing Windows services that can be instantiated numerous
times, each service instance having its own name. All services are using
the same log4net configuration file and we prefer to have all services
log to the same 'logs' folder. So the problem is to specialize the log
file name for each service. We do so thanks to an environment variable
that each process has to set at startup containing the service name, the
file name in the log4net config file contains a %ENV_VAR% that is
automatically replaced when log4net starts.
- Custom appender with non serializable fields:
We have a custom appender to perform asynchronous log. This appender
creates for the moment its own thread to work but I would prefer to have
the application creates it and assign it to the log4net appender. The
only solution I found so far is to have some kind of thread singleton
instance in the global scope of the application and then have the
appender retrieve it at construction.
You see in both situation I have to rely on a global storage which is a
design I always try to avoid because of the thread safety or maintenance
problems that comes with it. The following configuration would be much
more convenient:
- For the file customization I would prefer something like that:
Log4NetConfigurationSection section =
(Log4NetConfigurationSection)ConfigurationManager.GetSection("log4net");
string fileName =
section.Appenders["FileAppender"].Properties["File"].ToString();
section.Appenders["FileAppender"].Properties["File"] =
fileName.Replace("%SERVICE_NAME%", "Foo");
Log4NetConfigurator.Configure(section);
- For the thread problem I would see something like that:
Log4NetConfigurationSection section =
(Log4NetConfigurationSection)ConfigurationManager.GetSection("log4net");
Thread logThread = new Thread();
logThread.Name = "Log thread";
logThread.Start();
foreach (Appender appender in section.Appenders)
{
if (appender.Type == typeof(AsyncAppender))
{
appender.Properties["thread"] = logThread;
}
}
Log4NetConfigurator.Configure(section);
Of course the Appenders property would return an AppenderCollection
containing instances of a class which serialization is the <appender/>
config element.
So the idea is to have most of the configuration set in a config file
but still be able to tweak it programmatically. I hope I have been clear
this time.
Bests
Ron Grabowski wrote:
Log4net can be configured progmatically. Have you looked at the test cases for
examples?
----- Original Message ----
From: François Dumont <[EMAIL PROTECTED]>
To: log4net-dev@logging.apache.org
Sent: Wednesday, October 1, 2008 3:34:28 PM
Subject: Configuration system enhancement
Hi
We are using log4net through out all our applications and are very
happy with it. I would like to know however if you ever considered
enhancing the configuration system. I would be especially interested in
being able to fully initialize log4net programmatically. All the sample
I have been able to find are always using an xml description but there
are parameters we need to pass to a special appender we have develop
that simply cannot be serialized.
Bests
François Dumont