Additional Adapters in Spring - log4net
As log4net is a widely using logging framework, there are 2 additional adapters for log4net:
- Common.Logging.Log4Net
is linked against log4net 1.2.10.0
- Common.Logging.Log4Net129
is linked against log4net 1.2.9.0
2 different Adapters are necessary because log4net unfortunately changed it's public key from 1.2.9.0 to 1.2.10.0 (which was the primary reason for introducing Common.Logging)
Both Adapters accept the following configuration properties:
| Key | Possible Value(s) | Description |
| configType | FILE | INLINE will simply call XmlConfigurator.Configure() EXTERNAL expects log4net being configured somewhere else in your code and does nothing. FILE, FILE-WATCH: see property "configFile" below. |
| configFile | <path to your log4net.config file> | if configType is FILE or FILE-WATCH, the value of "configFile" is passed to XmlConfigurator.Configure (FileInfo) / ConfigureAndWatch(FileInfo) method. |
Example:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net">
<arg key="configType" value="FILE-WATCH" />
<arg key="configFile" value="~/log4net.config" />
</factoryAdapter>
</logging>
</common>
will configure log4net 1.2.10.0 using the file log4net.config from your application's root directory by calling XmlConfigurator.ConfigureAndWatch().
Advanced Logging Tasks
Implementing your own FactoryAdapter
If you need to implement your own FactoryAdapter, you need to implement the Common.Logging.ILoggerFactoryAdapter interface. An implementation must provide a public constructor accepting a NameValueCollection parameter:
public class MyLoggingFactoryAdapter : ILoggerFactoryAdapter
{
public MyLoggingFactoryAdapter(NameValueCollection properties)
{
// configure according to properties
}
public ILog GetLogger(Type type) { ... }
public ILog GetLogger(string name) { ... }
}