Home

ILoggerTCategoryName

ILoggerTCategoryName is the generic form of the logging interface used in the Microsoft.Extensions.Logging framework. It is defined as ILogger<TCategoryName> and inherits from ILogger, with the category name automatically derived from the type parameter TCategoryName. By default, the category represents the full type name, including its namespace, which helps organize and filter log output by source.

Usage typically involves dependency injection. In a class named OrderService, for example, a constructor can request

The typed logger provides the same logging capabilities as a non-generic ILogger, including Log, BeginScope, and

Configuration and filtering can target the specific category name derived from TCategoryName. For example, in appsettings.json

See also: Microsoft.Extensions.Logging, ILogger, ILoggerFactory, Dependency Injection, AppSettings configuration.

ILogger<OrderService>
and
store
it
for
later
use.
This
approach
ties
the
log
category
to
the
class
type,
making
logs
easy
to
trace.
For
instance,
you
would
log
messages
with
methods
such
as
LogInformation,
LogWarning,
or
LogError,
all
of
which
are
available
through
the
inherited
ILogger
interface
and
its
extension
methods.
the
standard
log
level
methods
(Information,
Warning,
Error,
Critical).
The
difference
is
that
the
category
name
is
fixed
at
compile
time
to
the
TCategoryName
type,
which
improves
clarity
and
enables
precise
category-based
filtering.
you
can
set
a
LogLevel
for
a
particular
namespace
and
class,
such
as
"MyApp.Services.OrderService",
while
leaving
other
categories
unaffected.
If
dynamic
category
names
are
needed,
an
alternative
is
to
create
a
non-generic
logger
via
ILoggerFactory.CreateLogger(string
categoryName).