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 what EventLogTraceListener
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 with TraceListener.TraceOutputOptions
. As for the additional variables, the most straightforward way would be to extend either the TraceSource
or one of the TraceListener
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.