0% found this document useful (0 votes)
4 views7 pages

Logging & Exception Handling Quiz Questions

The document contains 30 practice questions focused on logging and exception handling in ASP.NET Core. It covers topics such as log levels, namespaces, error handling mechanisms, and specific logging frameworks like Serilog and NLog. Each question tests knowledge on the purpose and functionality of logging features and error management in application development.

Uploaded by

kursat1927
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Logging & Exception Handling Quiz Questions

The document contains 30 practice questions focused on logging and exception handling in ASP.NET Core. It covers topics such as log levels, namespaces, error handling mechanisms, and specific logging frameworks like Serilog and NLog. Each question tests knowledge on the purpose and functionality of logging features and error management in application development.

Uploaded by

kursat1927
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

30 Practice Questions from Logging & Exception Handling (Week 11)

1. Which of the following log levels indicates a serious issue that causes the application
to crash?
LogDebug
LogInformation
LogWarning
LogCritical
LogTrace

2. In [Link] Core, which namespace provides the logging interfaces and classes?
[Link]
[Link]
[Link]
[Link]
[Link]

3. What is the purpose of using logging in an application?


To store user preferences
To directly improve code performance
To track behavior, debug issues, and monitor the system
To compile the application faster
To add animations to the UI

4. Which log level is commonly used to log general information about the normal
operation of an application?
LogError
LogDebug
LogInformation
LogTrace
LogCritical

5. How can you enable logging to the console in [Link] Core?


[Link]();
[Link]();
[Link]();
[Link]();
[Link](Console);

6. What is the purpose of the catch (Exception ex) block in error handling?
To stop compilation
To catch any type of unhandled exception
To speed up logging
To reset the application
To prevent logging

7. Which of the following is a benefit of using Serilog over the default logger?
It has no external dependencies
It uses XML for configuration
It is only used for console output
It supports structured logging with sinks for various targets
It replaces try-catch blocks

8. In the following line from Serilog output, what does "UserId" represent?
A system-level error
A reserved [Link] keyword
A fixed log value
A dynamic value provided during logging
A file path

9. What is the purpose of [Link]("/Home/Error") in [Link] Core?


To log only critical errors
To redirect console logs to a file
To provide a centralized global error handling mechanism
To create custom middleware
To use Serilog automatically

10. Which of the following statements about NLog is true?


NLog uses JSON files for configuration by default
NLog allows log messages to be customized via layout renderers
NLog is no longer supported
NLog cannot write to files
NLog only works in Windows environments

11. What happens if an exception is not caught in an [Link] Core application without
global error handling?
The exception is silently ignored
The application logs the error and continues
The application may crash or return an unhandled exception to the user
The application enters safe mode
A new thread is started to handle the exception

12. What is the main reason to use try-catch-finally blocks in code?


To stop code from running too quickly
To handle runtime errors and ensure final steps always run
To improve UI performance
To hide compile-time errors
To automatically retry operations

13. Which statement about custom exceptions is correct?


Custom exceptions cannot include messages
They must inherit from [Link]
They are only useful for debugging
They increase code clarity and should inherit from [Link]
They replace the need for logging

14. Which Serilog feature allows you to send logs to different targets like file, console,
or database?
Transformers
Outputs
Formatters
Sinks
Dispatchers

15. What does the following Serilog configuration do? .[Link]("logs/[Link]",


rollingInterval: [Link])
Writes logs to the event viewer
Archives logs only after application restart
Creates a new log file each day in the specified directory
Sends logs to a database
Deletes logs older than one day

16. What does the UseSerilog() method do in [Link]?


Removes default logging entirely
Automatically adds global exception handling
Replaces the default logger with Serilog
Writes logs only to console
Calls CreateHostBuilder() internally

17. What is a characteristic of structured logging?


Logs are stored in binary format
Only works with XML loggers
Logs are saved as key-value pairs for easier querying and analysis
Requires a database connection
Removes the need for log levels

18. In NLog, which file is typically used for configuration?


[Link]
[Link]
[Link]
[Link]
[Link]

19. In NLog configuration, what does this rule mean? <logger name="*"
minlevel="Debug" writeTo="file" />
Logs only errors to a file
Logs all messages from Debug level and above to a file
Ignores all logs below Error level
Prevents file logging unless exceptions occur
Applies only to Serilog
20. What is the result of calling [Link](ex, "The application terminated
unexpectedly."); in Serilog?
Ignores the error
Logs a critical fatal error and the exception message
Terminates the logger process
Restarts the application automatically
Logs to Visual Studio’s debug window only

21. Which of the following is NOT a built-in logging provider in [Link] Core?
Console
Debug
EventLog
LogStash
EventSource

22. Where do Console and Debug logging providers typically output log messages?
Only to a database
To terminal and Visual Studio output window respectively
To [Link]
Directly to Azure Monitor
To [Link]

23. What is the purpose of the finally block in exception handling?


To catch all exceptions
To define logging levels
To throw custom exceptions
To execute cleanup code regardless of exceptions
To skip code execution after a catch

24. Which log level would you use to log potentially harmful situations that are not
errors yet?
LogError
LogCritical
LogWarning
LogInformation
LogTrace

25. What must a custom exception class inherit from to be valid in .NET?
ILogger
[Link]
[Link]
[Link]
CustomError

26. What does ILogger<HomeController> represent in a controller class?


A static method
A hardcoded logger
A dependency-injected logging interface for that controller
A global configuration class
A base exception handler

27. What is the output of the following code if no exceptions occur? try { var result =
10 / 2; } catch (Exception ex) { [Link]("Error"); } finally {
[Link]("Process is done."); }
Error
Nothing
Process is done.
5
Error then Process is done.

28. What is the role of the .[Link]() setting in Serilog?


Disables debugging logs
Enables only critical error logs
Sets the minimum log level to capture, including Debug and above
Logs only to the console
Automatically clears previous logs

29. Which log level is the most detailed and usually disabled in production?
LogInformation
LogWarning
LogDebug
LogTrace
LogCritical

30. What does the following NLog layout output represent?


${longdate}|${level:uppercase=true}|${logger}|${message}
A JSON log format
A file path template
A custom format for text-based log output
A connection string
A loop execution summary

You might also like