Chad,

> I found that there is no real good way to configure log4net 
> at runtime. There is not a full API set for doing this and 
> what methods appear to provide some of the functionality 
> don't seem to work (they're used internally by log4net and 
> don't seem to be intended to be used externally).

The API is there for defining configuration at runtime, but it is not
strongly typed. This allows new appenders, layouts, etc to be written
without requiring changes to the log4net interfaces. This does mean that
configuring log4net programmatically isn't as easy as it could be.

One way to configure log4net is to embed an xml config file as an embedded
resource in your assembly and use that to configure logging.

Stream configStream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("LoggingConfig.xml
");
log4net.Config.DOMConfigurator.Configure(configStream);
configStream.Close();

This gives you the flexibility of the config file but without the deployment
issues.

Also the DOMConfigurator merges its changes into the repository, therefore
it would be possible to override this embedded configuration by using the
DOMConfigurator.ConfigureAndWatch(FileInfo) to monitor for an external
config file. This file does not have to exist, but if it does then it will
be loaded and merged into the repository.

Nicko

Reply via email to