Since there are so many logging frameworks out there, I was looking to write an abstraction per application so that I control which logging framework I can plugin. Meaning that I'm not reliable on for example Log4Net or NLog, but that I provide an interface/abstraction and then plugin frameworks in my own abstraction.
Something along these lines (a bit simplified mayvbe), which I can pass around to any object needing the dependency.
interface ILogger {
void LogMessage(string message, Severity severity);
void LogDebug(string message);
void LogInfo(string message);
void LogWarning(string message);
void LogError(string message);
void LogFatal(string message);
}
Afterwards my plan was to write adapters/implementations for the logging framework that I'd want to use - so I'd be able to plugin any other log framework when it is necessary.
public sealed class Log4NetLogger : ILogger {
/// Implementation and Log4Net specifics here
}
public sealed class NlogLogger : ILogger {
/// Implementation and Log4Net specifics here
}
These I'd inject/instantiate then via IoC or a resource locator, depending on the implementation details of the application I'm working on.
Question: I don't know if it would be a good idea? to write this from scratch, considering maybe
- loss of contextual information that's housed inside logging frameworks
- reinventing the wheel
- performance hit
On the other hand, the benefits for me are:
- If done correctly, I'd be able to switch out, or add a very custom implementation.
- I wouldn't need to touch the internals afterwards of classes that already exist and are in production, thus complying to solid and especially open/closed principle - introducing less bugs.
Any guidance, remarks, warnings DO's & DONT's - or maybe references to existing abstractions might be handy and are very welcome!
Thanks, Yves
LogParameters
abstract type that would contain possible common parameters for most of the frameworks, in either cases. One implicitly, one explicitly (like a guide abstract class). – welrockenLogDebug<TClass>()
so I can grab the class where it came from. Maybe also add the CallingMemberName attributes + params? That's a really good idea indeed. – Yves Schelpe