9

I was going through several blog posts at 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 Azure Application Insights.

Is it really necessary to use two approaches (NLog combined with AppInsights)? What if we simply use the AppInsight's 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.)

Are there any benefits of using both NLog and Application Insights? Do you think logging into a "local" database and into Azure is superfluous? Are there any drawbacks of using only Application Insights for both logging and tracing (latency, too expensive to call either time wise or money wise)?

AppInsight's 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);
}
Santhos
  • 321
  • 1
  • 3
  • 8
  • 1
    I know this is an old question, but what are you asking here, exactly? In general, questions containing words like "good idea" or "bad idea" are unanswerable; we don't know what those terms mean from the perspective of your specific problem context. – Robert Harvey Oct 06 '17 at 19:02
  • The question is about ApplicationInsights. If it is designed to be used instead of libraries like NLog and/or if it is a good idea to use it instead of NLog. – Santhos Oct 08 '17 at 16:43
  • I see you fellas went rampage on the topic. I am not sure what I meant a year ago, but now I would probably ask if ApplicationInsights is a tool only for telemetry or if it is suitable for general error logging/tracing. Give me few days to rewrite the question, but since it has some upvotes, I would say there were people who understood the question. I am really not sure why this started to bother anyone after a year :) – Santhos Oct 13 '17 at 06:49
  • The Stack Exchange software automatically bumped your post to the front page because it wasn't getting any attention. – Robert Harvey Oct 13 '17 at 14:43
  • I've revised the question and clarified it. Please, take a look. – Santhos Dec 27 '17 at 10:08

1 Answers1

-3

Having that ILog in your app is a good idea. This way you can just create a new implementation and swap it out. In your implementation you can do whatever you think is best. I hope you're using an IoC container to inject the ILog (or even better, injecting it into your pipeline without the ILog dependency everywhere). I typically only log to AI specific things I want to track. It does a great job out of the box already and tracing all requests even SQL calls, just about everything.