ILogger is the .NET logging abstraction for recording diagnostic messages. It lets application code report events without knowing whether logs go to the console, a file, or an external service. section 26.0 section 26.1.2
A logger carries several useful parts of a diagnostic record:
- Log level expresses importance, ranging from Trace to Critical. section 26.2 section 26.6
- Category identifies the component that created the message and supports filtering; ILogger<T> normally uses T's fully qualified name. section 26.2.2
- Message templates use named placeholders such as {RecipeCount}, preserving values for structured analysis. section 26.2 section 26.6
Injecting a logger into a Razor Page
Inject ILogger<IndexModel> through dependency injection, load the recipes, and call LogInformation("Loaded {RecipeCount} recipes", Recipes.Count). The configured providers receive the message, while RecipeCount remains available as a named value. section 26.2
Figure 26.3 The components of the ASP.NET Core logging framework. You register logging providers with an ILoggerFactory, which creates implementations of ILogger. You write logs to the ILogger, which delegates to the ILogger implementations that write logs to the console or a file. You can send logs to multiple locations with this design without having to configure the locations when you create a log message.
Follow the provider-to-factory-to-logger flow to see how one ILogger call can write to multiple destinations without changing application code. section 26.1.2




