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);
}