Question

I am the author of a C# open-source wrapper for a 3rd party service. I need to expose an ILogger facility (such as https://logging.apache.org/log4net/release/sdk/log4net.Core.ILogger.html) to log specific events and errors.

I could just go on and add a major logger such as Log4Net, but I don't want the wrapper to be tied to a specific logger.

I could just add an IoC container to easily solve this with a constructor dependecy injection but then again I don't want my wrapper to be tied to any specific IoC.

On the other hand it would be great if I could somehow expose the logging events to the consuming app (which is the one responsible for logging anyway) with the wrapper being agnostic towards its consumer.

Any thoughts on how to achieve this?

Was it helpful?

Solution

Projects will often provide their own abstraction. A default logger is bundled so things work out of the box, but you can easily configure the logging provider, as seen in ServiceStack logging and NServiceBus logging. For example:

LogManager.LogFactory = new Log4NetFactory(true);

There is also Common.Logging, which was designed to address the logging framework dependency issue. However, I have not seen it used extensively in major open source projects even though it's been around a while.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top