Home

ILoggerFactory

ILoggerFactory is an interface in the Microsoft.Extensions.Logging namespace that represents a factory for creating ILogger instances and coordinating logging providers. Its primary role is to supply loggers and to manage the set of providers that actually perform the logging work. The interface typically exposes a method to create a logger for a given category name and a method to register logging providers. In common implementations, it includes CreateLogger(string categoryName) and AddProvider(ILoggerProvider provider). It also implements IDisposable to allow proper resource cleanup when the factory is no longer needed.

Providers and logging pipeline: The factory delegates logging to a collection of ILoggerProvider instances. Each provider

Typical usage: In modern .NET applications, logging configuration is usually wired up through a host or service

Relationship to other components: ILoggerFactory works with ILogger and ILoggerProvider. The factory creates loggers that use

implements
the
details
of
how
and
where
log
messages
are
written
(for
example,
to
the
console,
debug
output,
or
a
file)
and
respects
configured
log
levels
and
filters.
By
aggregating
providers,
the
factory
enables
a
unified
configuration
for
multiple
destinations.
container,
which
registers
one
or
more
providers
and
creates
loggers
automatically.
Developers
can
obtain
an
ILoggerFactory
via
dependency
injection,
or
create
and
use
a
logger
directly
through
the
factory
by
calling
CreateLogger
with
a
category
name.
For
many
scenarios,
injecting
ILogger<T>
into
a
component
is
preferred,
with
the
framework
resolving
the
appropriate
logger
category.
one
or
more
providers
to
emit
log
events,
enabling
flexible,
extensible
logging
across
applications.