Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
    
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 6:31

2 Answers 2

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.

share|improve this answer
    
What existing framework features are you talking about? Or did you mean existing libraries? –  svick Apr 27 '13 at 9:04
    
@svick: I'm talking about System.Diagnostics.TraceSource and related classes. –  MainMa 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. –  Mike 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 or for learning purposes. –  MainMa Apr 27 '13 at 15:46

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.
share|improve this answer
    
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 9:03
    
@svick: I've expanded the answer accordingly. –  Michael Borgwardt Apr 27 '13 at 9: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. –  MainMa 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. –  sukumar Apr 27 '13 at 16:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.