I faced a question in a .NET interview.
As a client i need a LoggingAPI. How you go the approach of design and development and delivering Logging API to the client? I don’t care about WPF or a language specific. I want a LoggingAPI which has to log some data? what is your approach in delivering the same.
I failed to answer for this question. Please guide how to proceed for answering this type of questions.
1
The interview question isn’t clear enough. A client needs a logging API to do what? What’s wrong with existent .NET Framework features?
Case 1: they were testing your analysis skills
Maybe they were expecting you to ask those precise questions, the intent being to make sure you have enough experience in elucidating the requirements and understanding the problem, instead of just starting to write code with no thought about the problem itself, like beginners usually do.
As a developer, you’re expected to solve problems and the fastest, less expensive and most elegant way, not to simply type code. When you’re asked to “create a blog engine which could be deployed in LAMP environment”, if your first reflex is to create a new PHP file and to start typing, you’re doing it wrong. Instead, you’re expected to either know or go, search and find that there is already a product called WordPress that you can use, reducing the cost and delivery time, while increasing the final quality.
In real life, it happens like that:
— We need a logging API. What would be your approach of design, development and delivery?
— Wait, why can’t you use log4net?
— Because we don’t want additional libraries [one of the most stupid arguments, but sadly you rarely can reply this to the customer].
— What about .NET Framework logging?
— No. We need something powerful with lots of features.
— Ok. What features do you need which are not already available in .NET Framework?
— We need to be able to save some entries to the Windows Event Log, not simply to text files.
— This is whatEventLogTraceListener
does.
— Really? I didn’t know that. Well, it’s still not an option, because we need to include, with every trace event, the date and time of the event, as well as some debug values which are in a static class. Those values give us precious information about the state of the system.
— The date and time are added withTraceListener.TraceOutputOptions
. As for the additional variables, the most straightforward way would be to extend either theTraceSource
or one of theTraceListener
s to include the values of those variables.
Case 2: they were checking if you know how logging APIs are done
Maybe they were expecting you to describe the architecture of a logging library. In which case you were expected to tell that it should have:
-
Types (for example verbose, information, warning and error),
-
Listeners; this enables the user to attach one or more listeners like the one which logs the information to a file, or one which outputs it to the console, or one which saves the logs in the database or as Windows Events,
-
Filtering, i.e. each listener may want to listen to the logs from one component of an application, but not another, or a listener may be interested in only errors and warnings, while another one will record everything,
It should also be aware of concurrency issues. Writing logs to the same file from two threads would inevitably cause problems.
Being able to configure different options, especially the log level, at runtime (for example through App.config) is also nice to have.
4
How you go the approach of design and development and delivering Logging API to the client?
The first (and usually only) thought would be to use one of the many mature, tested and well-known existing logging libraries.. As for which one if the client doesn’t care, use what you know best or what seems to be most popular.
This is if it’s supposed to be a real world scenario, which it sounds like when talking about a client. It may be that the interviewers really wanted to test your understanding of how logging APIs are designed, so it might be best to first clarify that.
To gain the undestanding, it would be best to take a look at various logging libraries to see what they have in common. Typical elements are:
- log levels that allow you to specify how important a log message is and allow the system to log only those above a certain level
- a way to associate log messsages with modules (or classes, packages, namespaces…) so you can have per-module output and configuration
- Various logging targets (log to a file, a DB, send emails, etc.)
- a way to configure all of the above.
4