ASP.NET Core Interview

Logging, Error Handling & Background Services

ASP.NET Core interview questions covering logging, error handling & background services.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
151
Mid-LevelIntermediate

What is logging in ASP.NET Core?

Logging is the framework-supported mechanism for recording diagnostic and operational information about an application. ASP.NET Core provides the ILogger abstraction so application code can write logs without being tightly coupled to a particular logging provider.

152
Mid-LevelIntermediate

What is ILogger<T> in ASP.NET Core?

ILogger<T> is a typed logging abstraction provided through dependency injection. The generic type normally identifies the class producing the log and becomes the logging category.

153
Mid-LevelIntermediate

What are the standard log levels in ASP.NET Core?

ASP.NET Core logging defines Trace, Debug, Information, Warning, Error, Critical, and None levels.

154
Mid-LevelIntermediate

How is logging configured in ASP.NET Core?

Logging configuration can be supplied through appsettings.json, environment-specific configuration, code, and provider-specific settings. Categories can have different minimum log levels.

155
Mid-LevelIntermediate

What are logging providers in ASP.NET Core?

A logging provider sends log events to a particular destination or logging system. Built-in and platform integrations can write to destinations such as the console, debug output, event sources, or operating-system logging facilities.

156
Mid-LevelIntermediate

What is structured logging?

Structured logging records named properties alongside a message template instead of building one long formatted string. Those properties can be indexed and queried by log-management systems.

157
Mid-LevelIntermediate

What is a logging scope?

A logging scope attaches contextual information to a group of log entries produced during an operation. Providers that support scopes can include this context in every log event inside the scope.

158
Mid-LevelIntermediate

How should exceptions be logged in ASP.NET Core?

When an exception is logged, pass the Exception object to the logging method so the provider can record its type, message, stack trace, and inner-exception information.

159
Mid-LevelIntermediate

How can you implement centralized exception handling?

Centralized exception handling keeps repetitive try/catch blocks out of controllers and provides consistent responses for unhandled failures.

160
Mid-LevelIntermediate

What is Problem Details in ASP.NET Core?

Problem Details is a standardized JSON format for describing HTTP API errors. It commonly contains fields such as type, title, status, detail, and instance, with optional extension properties.

161
Mid-LevelIntermediate

What is BackgroundService in ASP.NET Core?

BackgroundService is a base class for implementing long-running hosted services. A derived class overrides ExecuteAsync and performs work until the supplied cancellation token indicates that the host is shutting down.

162
Mid-LevelIntermediate

What is IHostedService?

IHostedService defines the contract for services whose lifetime is managed by the .NET host. It contains StartAsync and StopAsync methods.

163
Mid-LevelIntermediate

How do you register a hosted service?

Hosted services are normally registered with AddHostedService<T>(). The host creates and manages the service as part of application startup and shutdown.

164
Mid-LevelIntermediate

How should a BackgroundService use scoped services such as DbContext?

A hosted BackgroundService is long-lived, whereas DbContext is normally scoped. Injecting the DbContext directly into the worker would create a lifetime mismatch.

165
Mid-LevelIntermediate

Why is CancellationToken important in ASP.NET Core?

CancellationToken allows asynchronous operations to stop cooperatively when work is no longer required. In HTTP processing, RequestAborted can signal that the client disconnected. In hosted services, the stopping token signals application shutdown.

166
Mid-LevelIntermediate

What is graceful shutdown in ASP.NET Core?

Graceful shutdown allows the application to stop accepting new work and gives in-progress operations and hosted services an opportunity to finish or cancel cleanly.

167
Mid-LevelIntermediate

How can periodic background work be implemented safely?

Periodic work can be implemented with a BackgroundService and PeriodicTimer. Each iteration should observe the cancellation token, handle failures deliberately, and avoid overlapping executions unless concurrency is intentional.

168
Mid-LevelIntermediate

What happens if a BackgroundService throws an unhandled exception?

An unhandled exception escaping a background service is a serious application failure. Host behavior is configurable, but modern .NET hosting commonly treats an unhandled BackgroundService exception as a reason to stop the host rather than silently leaving the application running without an expected worker.

169
Mid-LevelIntermediate

How should retry logic be designed for background work?

Retries should be used only for failures that are plausibly transient, such as a temporary network or service outage. Permanent validation errors, authentication failures, or invalid business data should not be retried indefinitely.

170
Mid-LevelIntermediate

What is correlation ID and why is it useful?

A correlation ID is an identifier used to associate logs and operations that belong to the same request or distributed workflow.

171
Mid-LevelIntermediate

What is health checking in ASP.NET Core?

Health checks expose application health information that infrastructure can use to determine whether an instance is functioning or ready to receive traffic.

172
Mid-LevelIntermediate

What is the difference between liveness and readiness checks?

A liveness check answers whether the application process is alive enough that restarting it may be appropriate when the check fails. It should usually avoid fragile dependency checks that could cause unnecessary restart loops.

173
Mid-LevelIntermediate

What is the difference between logging, metrics, and tracing?

Logs record discrete events and diagnostic details. Metrics are numerical measurements aggregated over time, such as request rate, error count, latency, memory usage, or queue depth. Traces follow the path and timing of an operation across components and services.

174
Mid-LevelIntermediate

How should sensitive information be handled in logs?

Sensitive information should not be logged unless there is a specific, justified, and protected requirement. Passwords, authentication tokens, secret keys, full connection strings, payment credentials, and other confidential values should never appear in ordinary application logs.

175
Mid-LevelIntermediate

What are best practices for logging, error handling, and background services in ASP.NET Core?

Use structured ILogger messages with meaningful properties and appropriate log levels. Centralize unhandled exception processing, return safe and consistent production errors, and preserve detailed diagnostics in protected logs rather than exposing them to users.