This question is related to Steven s answer - here . He offered very good packaging for the logger. I will insert his code below:
public interface ILogger { void Log(LogEntry entry); } public static class LoggerExtensions { public static void Log(this ILogger logger, string message) { logger.Log(new LogEntry(LoggingEventType.Information, message, null)); } public static void Log(this ILogger logger, Exception exception) { logger.Log(new LogEntry(LoggingEventType.Error, exception.Message, exception)); }
So my question is: how to create an implementation whose proxy server is connected to log4net ? Should I just add another log extension method with a type parameter and then create a switch inside? Use another log4net method in case of LoggingEventType ?
And the second question, what is the best way to use it later in the code?
Because he wrote:
(...) you can easily create an implementation of ILogger (...) and configure your DI container to inject it into classes that have an ILogger constructor.
Does this mean that every class that will write sth (so basically everyone) should have an ILogger in its constructor?
Tim Laax Sep 01 '15 at 23:16 2015-09-01 23:16
source share