Should I be using the ILog or ILogger interface? I find the ILog interface to be easier to use since I can just declare one instance per class by calling:
private ILog _logger = LogManager.GetLogger(typeof(MyClass));
It's a much simpler interface then the ILogger:
void Log(Type callerStackBoundaryDeclaringType, Level level, object message, Exception exception)
Is there a difference? When is it better to use 1 vs the other?
ILogger. ILogger is a logger that your code can use to write log messages to. There are three core methods: IsEnabled tests whether a log level is enabled on that logger; Log is the core logging method that is used to write log messages; and BeginScope defines a logging scope.
ILogger: is responsible to write a log message of a given Log Level. ILoggerFactory: you can register one or more ILoggerProvider s with the factory, which in turn uses all of them to create an instance of ILogger . ILoggerFactory holds a collection of ILoggerProviders .
You can create logs using the ILogger interface, which is injected into your code by the ASP.NET Core dependency injection container. The following example illustrates this. using System; using System. Collections.
ILoggerFactory Interface ILoggerFactory is a factory interface that we can use to create instances of the ILogger type and register logging providers. It acts as a wrapper for all the logger providers registered to it and a logger it creates can write to all the logger providers at once.
I recommend the ILog
interface. This has been pushed by Apache/Common Logging. If you use the common logging interface, then most logging systems can be plugged into your application.
I find log4net to be more than adequate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With