Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ILog or ILogger?

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?

like image 614
Micah Avatar asked Jun 14 '11 01:06

Micah


People also ask

What is an ILogger?

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.

What is the difference between ILogger and ILoggerFactory?

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 .

What is ILogger in asp net core?

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.

What is ILogger factory?

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.


1 Answers

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.

like image 145
Richard Schneider Avatar answered Sep 19 '22 04:09

Richard Schneider