As per usage of ILogger in your .net core which is depends of your requirements.
ILogger
ILogger
is a logger that your code can use to write log messages.
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;
BeginScope
defines a logging scope.
There’s a bunch of logging extension methods that build on that core; the common methods like LogInformation
are just wrappers around Log
, with the appropriate arguments.
Internally, an ILogger
has a “name” (also called a “category”). The idea is that each ILogger
instance is used by a different component of the application.
ILogger
is a base interface that provides the core logging functionality, but it is seldom used directly. There are some exceptions (e.g., Azure Functions will pass you an ILogger
), but most of the time your code will log to an ILogger<T>
.
ILogger
ILogger<T>
is a logger that is named after a type T
. All logs sent to an ILogger<T>
(with the default implementation) will have a logger name/category of typeof(T).FullName
. ILogger<T>
is derived from ILogger
and adds no new functionality.
If you’re using dependency injection, an instance of ILogger<T>
is usually injected into your type T
. So, each time you have a constructor that takes an ILogger<T>
, you are defining a “component” for your application.
Majar usage of difference
If you want to log your data as Typed log (serilog, etc., ) you can use ILogger< T>
or you want to use untyped logs you can simply use ILogger
ASP.NET Core apps, encourage you to use standard Serilog
interfaces like Log
, ILogger
, and LogContext
if they meet your needs.
Alternatively, your app can consume the ILogger interface from the framework via dependency injection. Serilog implements this interface, so the results are identical for practical purposes.
The ILoggerFactory
logger factory instance is the boostrapper of the logging system: It is used to attach logger providers and create logger instances - either typed (ILogger<T>
) or untyped (ILogger
). These logger instances will log to all registered logger providers.
Refer Ilogger best practices & Usage of logging