.netcommon.logging

Common.Logging with multiple factory adaptors


I am currently working on moving a large project over to use Common.Logging and I was hoping to be able to output logging events to more than one 3rd party logging implementation.

We currently have an internally developed tracing library that we would like to keep using for tracing and debugging messages. I would also like to start using log4net to sent some messages to a database for reporting or send email notifications at some levels.

What I'm looking for is something like this:

<common>
<logging>
  <factoryAdapter type="CustomTraceFactoryAdapter, MyAssembly">
    <arg key="configType" value="INLINE"/>
  </factoryAdapter>
  <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
    <arg key="configType" value="INLINE"/>
  </factoryAdapter>
</logging>
</common>

Is there any way to do this with the out of the box configuration options?


Solution

  • AFAIK, nothing exists in Common.Logging for what you need. Here are a couple of alternatives.

    1) Develop a couple of custom logger factory adaptor as described at http://netcommon.sourceforge.net/docs/2.1.0/reference/html/ch01.html#logging-advanced-customfactoryadapter. One custom factory, which it appears you have already developed, would be for your internal tracing library. The second custom factory would create composite logger objects by combining loggers from one or more other factories.

    2) Develop a custom log4net appender (http://logging.apache.org/log4net/release/faq.html#custom-appender) for your tracing library and configure Common.Logging to only use the log4net factory.

    I feel the second option would be easiest as it would not involve changing the configuration behavior of Common.Logging so it can constitute the composite factory from other configured factories.