Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to create a simple system to abstract logging platforms. The idea is that

ID: 645935 • Letter: I

Question

I need to create a simple system to abstract logging platforms. The idea is that I'd like to be able to exchange or activate a logging platform (nlog, log4net, enterprise library) via some configuration (this shouldn't be a problem). I know that I would need a wrapper for each platform that I want to support that would load the necessary dll's and create the loggers.

I was thinking of creating an abstract class or an interface providing the most common methods like Log, Debug, Trace, etc.:

interface ILogger
{
    void Log(...);
    void Debug(...);
    // etc.
}

class NLogPlatform : ILogger
{
    // create nlog, load config etc.
}

class Log4NetPlatform : ILogger
{
    // create log4net, load config etc.
}

class LoggerFactory
{
    public static CreateLogger(...)
    {
        // read settings and create a logger.
    }
}
At first I thought of a log-provider but then I found that provider is not a pattern at all so I looked at .NET Design Patterns but nothing really seems to be suitable here. Did I miss something or is there just no pattern for it?

I haven't really started yet because this time I'd rather go in the right direction from the beginning then refactor several tools later.

Could you tell me what I should take into consideration when designing such a system and whether there is a pattern for this?

Explanation / Answer

Congratulations, you have (re-)discovered the Object Adapter Pattern. You have one target interface (here: ILogger), and various adapter classes NLogPlatform, Log4NetPlatform,

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote