Configuration & Logging Flashcards
6 cards from real ASP.NET Core practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Configuration & Logging flashcards as text
What is IOptionsSnapshot used for in ASP.NET Core?
Answer: To get a scoped options value that reflects configuration changes between requests
IOptionsSnapshot recomputes options per request scope, allowing configuration file changes to take effect without restarting.
Which method adds Serilog as the host logging provider in the minimal hosting model?
Answer: builder.Host.UseSerilog()
builder.Host.UseSerilog() replaces the default .NET logging with Serilog on the generic host level.
What does the ASPNETCORE_ENVIRONMENT environment variable control?
Answer: The active environment name, affecting which appsettings and middleware are loaded
ASPNETCORE_ENVIRONMENT sets IWebHostEnvironment.EnvironmentName, switching between Development, Staging, and Production behaviors.
What is the purpose of IConfiguration.GetConnectionString("name") in ASP.NET Core?
Answer: It retrieves the connection string from the ConnectionStrings section by name
GetConnectionString() is a shorthand for configuration.GetSection("ConnectionStrings")[name], a conventional location for connection strings.
Which method validates options at startup and throws if the configuration is invalid?
Answer: services.AddOptions().ValidateDataAnnotations().ValidateOnStart()
ValidateDataAnnotations() checks data annotation attributes, and ValidateOnStart() ensures validation occurs at app launch rather than first use.
What is a logging scope in ASP.NET Core?
Answer: A context block that adds additional structured data to all log messages within it
Using logger.BeginScope() attaches ambient key-value data to all log events within the scope block.