Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was going through several blog posts and stackoverflow and programmers and I am still a bit confused. You can install NLog (or some other logging lib) and start logging quite fast and then you can install the application insights and an adapter to actually gather the data into the app insights.

Is it really necessary? What if we simply use the TelemetryClient to log and trace. If I want to go fancy, I can wrap it with an interface, so I can easily change it later on. I can even wrap it in Common.Logging to be even fancier. (I would be really fancy there.)

Is it a poor design idea to log and trace with App Insights TelemetryClient only? Let me give you an example, imagine you have a DI container somewhere:

ILog.cs

public interface ILog
{
    void Exception(Exception ex);
}

TelemetryClientLog.cs

public class TelemetryClientLog : ILog
{
    private readonly TelemetryClient telemetryClient = null;

    public TelemetryClientLog(TelemetryClient telemetryClient)
    {
        this.telemetryClient = telemetryClient;
    }

    public void Exception(Exception ex)
    {
        this.telemetryClient.TrackException(ex);
    }
}

StarWars.cs

// somewhere in a code far far away with an injected logger
try
{
    this.CallJedi();
}
catch(LightSaberException lse)
{
   // log implements ILog interface, look above
   this.log.Exception(lse);
}
share|improve this question

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.