ASP.NET Core Configuration & Logging 2 — Questions and Answers
Question 1: Which interface is used to write log messages in ASP.NET Core applications?
- ILogger<T> (Correct answer)
- ILog
- IApplicationLogger
- ILogWriter
Correct answer: ILogger<T>
ILogger<T> is the generic logging interface injected via DI, scoping logs to the category name derived from T.
Question 2: What is the lowest severity log level in ASP.NET Core logging?
- Trace (Correct answer)
- Debug
- Information
- Verbose
Correct answer: Trace
Trace is the most verbose level, intended for detailed diagnostic messages, typically disabled in production.
Question 3: Which method logs a message at the Error level using ILogger?
- logger.LogError(message) (Correct answer)
- logger.Error(message)
- logger.Log(LogLevel.Error, message)
- logger.WriteError(message)
Correct answer: logger.LogError(message)
ILogger provides convenience methods like LogError(), LogWarning(), and LogInformation() for each log level.
Question 4: What does the Logging:LogLevel:Default configuration key control?
- The minimum log level for all categories that don't have a specific override (Correct answer)
- The default log provider to use
- The output format of log messages
- The maximum number of log entries stored
Correct answer: The minimum log level for all categories that don't have a specific override
Logging:LogLevel:Default sets the baseline minimum severity; categories with specific entries override this default.
Question 5: Which NuGet package provides structured logging with Serilog in ASP.NET Core?
- Serilog.AspNetCore (Correct answer)
- Serilog.Extensions.Logging
- Microsoft.Extensions.Serilog
- AspNetCore.Serilog
Correct answer: Serilog.AspNetCore
Serilog.AspNetCore integrates Serilog as the logging provider, replacing the default Microsoft logging pipeline.
Question 6: What is structured logging in the context of ASP.NET Core?
- Logging with named placeholders that capture values as structured data, not just strings (Correct answer)
- Writing logs to a structured database table
- Logging in XML or JSON format only
- Using log levels and categories together
Correct answer: Logging with named placeholders that capture values as structured data, not just strings
Structured logging captures log message parameters as individual fields (e.g., UserId=42) enabling powerful filtering and querying.
Which interface is used to write log messages in ASP.NET Core applications?