What is the primary purpose of error handling in ASP.NET?
a. To manage exceptions and provide a way to recover or gracefully handle errors in applications
b. To optimize database performance
c. To handle user authentication
d. To manage application state
Answer: a. To manage exceptions and provide a way to recover or gracefully handle errors in applications
Which method is used in ASP.NET MVC to handle exceptions globally?
a.
Application_Error()
b.
HandleErrorAttribute
c.
OnException()
d.
Try-Catch
Answer: b.
HandleErrorAttribute
What does the
try-catch
block in C# do?
a. It catches exceptions that occur in the
try
block and handles them in the
catch
block
b. It handles regular statements
c. It manages application state
d. It performs data encryption
Answer: a. It catches exceptions that occur in the
try
block and handles them in the
catch
block
Which method is commonly used to log exceptions in ASP.NET Core applications?
a.
ILogger.LogError()
b.
Exception.WriteLog()
c.
Trace.WriteLine()
d.
Console.WriteLine()
Answer: a.
ILogger.LogError()
What is the purpose of the
finally
block in exception handling?
a. To execute code that must run regardless of whether an exception was thrown or not
b. To handle exceptions
c. To optimize performance
d. To manage application state
Answer: a. To execute code that must run regardless of whether an exception was thrown or not
How can you configure custom error pages in ASP.NET Core?
a. By modifying the
Startup.cs
file to use
app.UseExceptionHandler()
b. By editing the
web.config
file
c. By updating the
appsettings.json
file
d. By changing the
Global.asax
file
Answer: a. By modifying the
Startup.cs
file to use
app.UseExceptionHandler()
What does the
Application_Error()
method do in ASP.NET Web Forms?
a. It handles unhandled exceptions that occur during the processing of an HTTP request
b. It performs data encryption
c. It manages user sessions
d. It handles database queries
Answer: a. It handles unhandled exceptions that occur during the processing of an HTTP request
Which attribute is used to log errors in ASP.NET MVC controllers?
a.
HandleErrorAttribute
b.
ErrorLoggerAttribute
c.
ExceptionHandlerAttribute
d.
ExceptionLoggingAttribute
Answer: a.
HandleErrorAttribute
How can you implement logging in an ASP.NET Core application?
a. By using built-in logging providers such as Console, Debug, and File
b. By writing custom logging logic
c. By using SQL Server for logging
d. By creating global variables
Answer: a. By using built-in logging providers such as Console, Debug, and File
What is the role of
IExceptionFilter
in ASP.NET Core?
a. To provide a way to handle exceptions that occur during the execution of an action
b. To log data
c. To manage user sessions
d. To optimize performance
Answer: a. To provide a way to handle exceptions that occur during the execution of an action
Which ASP.NET Core middleware can be used for exception handling and logging?
a.
UseExceptionHandler()
b.
UseMiddleware<LoggingMiddleware>()
c.
UseStaticFiles()
d.
UseAuthentication()
Answer: a.
UseExceptionHandler()
How can you capture detailed error information in ASP.NET Core?
a. By enabling developer exceptions page with
app.UseDeveloperExceptionPage()
b. By using custom error pages
c. By modifying the
web.config
file
d. By using SQL queries
Answer: a. By enabling developer exceptions page with
app.UseDeveloperExceptionPage()
What is the benefit of using structured logging in ASP.NET Core?
a. It allows for capturing log data in a structured format, which is useful for querying and analysis
b. It improves application performance
c. It provides data encryption
d. It handles user authentication
Answer: a. It allows for capturing log data in a structured format, which is useful for querying and analysis
Which method can be used to log warnings in ASP.NET Core?
a.
ILogger.LogWarning()
b.
Exception.LogWarning()
c.
Trace.WriteWarning()
d.
Console.WriteWarning()
Answer: a.
ILogger.LogWarning()
What does the
Error Handling Middleware
in ASP.NET Core do?
a. It catches and handles exceptions that occur during the processing of HTTP requests
b. It manages user sessions
c. It encrypts data
d. It handles database transactions
Answer: a. It catches and handles exceptions that occur during the processing of HTTP requests
How can you configure global exception handling in an ASP.NET MVC application?
a. By using
Application_Error()
in
Global.asax
b. By using
HandleErrorAttribute
on controllers or actions
c. By using
web.config
d. By modifying
Startup.cs
Answer: b. By using
HandleErrorAttribute
on controllers or actions
What is the purpose of
ILogger
in ASP.NET Core?
a. To provide a logging mechanism that can be used across the application
b. To handle exceptions
c. To manage user sessions
d. To perform data encryption
Answer: a. To provide a logging mechanism that can be used across the application
What does
UseExceptionHandler()
middleware do in ASP.NET Core?
a. It provides a way to handle exceptions and show custom error pages
b. It logs data to the console
c. It performs data encryption
d. It handles user authentication
Answer: a. It provides a way to handle exceptions and show custom error pages
Which logging level is used to indicate an error in the application?
a. Error
b. Debug
c. Information
d. Trace
Answer: a. Error
How can you create a custom logging provider in ASP.NET Core?
a. By implementing
ILoggerProvider
and
ILogger
interfaces
b. By using
ILoggerFactory
c. By modifying
Startup.cs
d. By using
Application_Error()
Answer: a. By implementing
ILoggerProvider
and
ILogger
interfaces
What is the purpose of the
LogLevel
enum in ASP.NET Core logging?
a. To specify the severity of the log message, such as Information, Warning, Error
b. To manage user sessions
c. To perform data encryption
d. To handle database transactions
Answer: a. To specify the severity of the log message, such as Information, Warning, Error
Which method in ASP.NET Core is used to add logging services to the dependency injection container?
a.
services.AddLogging()
b.
services.AddTransient<ILogger>()
c.
services.AddDbContext()
d.
services.AddScoped<IExceptionFilter>()
Answer: a.
services.AddLogging()
How can you log exception details including stack traces in ASP.NET Core?
a. By using
ILogger.LogError()
method with exception details
b. By writing exceptions to a file manually
c. By using
Trace.WriteLine()
d. By using
Console.WriteLine()
Answer: a. By using
ILogger.LogError()
method with exception details
Which feature allows you to display a friendly error page in ASP.NET Core?
a.
UseExceptionHandler()
b.
UseStaticFiles()
c.
UseRouting()
d.
UseAuthentication()
Answer: a.
UseExceptionHandler()
What is the role of
Exception Filters
in ASP.NET MVC?
a. To handle and process exceptions that occur during the execution of actions
b. To log data
c. To manage user sessions
d. To encrypt data
Answer: a. To handle and process exceptions that occur during the execution of actions
How can you capture and log exceptions in an ASP.NET Core Web API application?
a. By using middleware and logging within
Configure
method of
Startup.cs
b. By using
Global.asax
c. By modifying
web.config
d. By using
Application_Error()
Answer: a. By using middleware and logging within
Configure
method of
Startup.cs
Which class in ASP.NET Core provides methods for logging information about the application?
a.
ILogger
b.
LogManager
c.
TraceSource
d.
EventLog
Answer: a.
ILogger
What is a common practice to prevent logging sensitive data?
a. Ensure that logging does not include sensitive information such as passwords or personal data
b. Log everything to a file
c. Use debugging tools to capture sensitive data
d. Include all data in log messages
Answer: a. Ensure that logging does not include sensitive information such as passwords or personal data
How can you handle exceptions in ASP.NET Core Web API and return custom error responses?
a. By using exception handling middleware and returning
IActionResult
responses
b. By using
Application_Error()
c. By modifying
web.config
d. By using
Global.asax
Answer: a. By using exception handling middleware and returning
IActionResult
responses
What is the purpose of logging in web applications?
a. To monitor application performance and troubleshoot issues
b. To manage user authentication
c. To handle database queries
d. To optimize performance
Answer: a. To monitor application performance and troubleshoot issues
Which logging provider in ASP.NET Core writes logs to the console?
a. Console Logger
b. File Logger
c. Debug Logger
d. EventSource Logger
Answer: a. Console Logger
What is a
Serilog
in the context of ASP.NET Core?
a. A structured logging library that provides advanced logging capabilities
b. A middleware for error handling
c. A class for session management
d. A tool for data encryption
Answer: a. A structured logging library that provides advanced logging capabilities
What is the default logging level for
ILogger
in ASP.NET Core?
a. Information
b. Debug
c. Warning
d. Error
Answer: a. Information
How can you log information only when the application is running in a development environment?
a. By using
ILogger
with conditional logging based on the environment
b. By setting logging levels in
web.config
c. By using
Trace.WriteLine()
d. By configuring
Global.asax
Answer: a. By using
ILogger
with conditional logging based on the environment
Which class can be used for file-based logging in ASP.NET Core?
a.
FileLogger
b.
FileLogProvider
c.
LoggerFactory
d.
ILogger
Answer: a.
FileLogger
How do you configure logging to write to a text file in ASP.NET Core?
a. By using a third-party logging provider like Serilog with file sinks
b. By writing logs directly to the file system
c. By using
Trace.WriteLine()
d. By modifying
web.config
Answer: a. By using a third-party logging provider like Serilog with file sinks
Which method in
ILogger
is used to log critical errors?
a.
LogCritical()
b.
LogError()
c.
LogWarning()
d.
LogInformation()
Answer: a.
LogCritical()
How can you ensure logging does not impact application performance significantly?
a. By configuring appropriate log levels and using asynchronous logging
b. By logging everything synchronously
c. By writing logs to a central server directly
d. By using excessive logging
Answer: a. By configuring appropriate log levels and using asynchronous logging
What does the
LogLevel
enum represent in ASP.NET Core?
a. Different levels of logging severity such as Information, Warning, Error, and Critical
b. The method of logging data
c. The storage location of log files
d. The type of logging provider
Answer: a. Different levels of logging severity such as Information, Warning, Error, and Critical