2

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.

venkat
  • 129
  • 1
  • I think it comes down to experience. If you ever had to develop an API and had experience working with some logging library, it should be easy. – Euphoric Apr 27 '13 at 06:31

2 Answers2

7

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 TraceListeners 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.

Arseni Mourzenko
  • 134,780
  • 31
  • 343
  • 513
  • What existing framework features are you talking about? Or did you mean existing libraries? – svick Apr 27 '13 at 09:04
  • @svick: I'm talking about `System.Diagnostics.TraceSource` and related classes. – Arseni Mourzenko Apr 27 '13 at 13:12
  • I was going to write the same answer. But I'd add that they usually want to see both. How do you go about gathering detailed requirements AND what are your design skills once you have them. – Michael Brown Apr 27 '13 at 15:28
  • @MikeBrown: Want to see both cases during the interview? Then it wouldn't be difficult to fit both answers to the interviewer: first discussing the fact that logging API already exists and there is no need to reinvent the wheel, then explaining how would one implement a similar logging API [for fun](http://programmers.stackexchange.com/a/55407/6605) or for learning purposes. – Arseni Mourzenko Apr 27 '13 at 15:46
3

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.
Michael Borgwardt
  • 51,037
  • 13
  • 124
  • 176
  • Since this is an interwiew questions, I think a folloup question after an answer like this would be: "Okay, but what if you couldn't/didn't want to use an existing library?" – svick Apr 27 '13 at 09:03
  • @svick: I've expanded the answer accordingly. – Michael Borgwardt Apr 27 '13 at 09:15
  • @svick: "what if you couldn't/didn't want to use an existing library?": then you may ask the interviewer what exactly is the issue which makes it impossible to use the logging feature of .NET Framework, nor any of the existent libraries. Chances are that instead of rewriting the whole thing, you may simply extend what is already written and well-tested. – Arseni Mourzenko Apr 27 '13 at 13:17
  • @MichaelBorgwardt: Can you provide/share me any realtime example interms of Design,Development and Deployment of LoggingAPI UI. First i was unable to answer interviewer when he asked about the same? Please help me how to start to answer for this question and this type of questions to the interviewer. – venkat Apr 27 '13 at 16:28