Just a few small changes to my NLog sample logging to Azure Application Insights.
I modified the application so I could provide the InstrumentationKey via the command line or the ApplicationInsights.Config file.(I have a minimalist config for this sample)
namespace devMobile.Azure.ApplicationInsightsNLogClient { class Program { private static Logger log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString()); static void Main(string[] args) { if ((args.Length != 0) && (args.Length != 1)) { Console.WriteLine("Usage ApplicationInsightsNLogClient"); Console.WriteLine(" ApplicationInsightsNLogClient <instrumentationKey>"); return; } if (args.Length == 1) { TelemetryConfiguration.Active.InstrumentationKey = args[0]; } log.Trace("This is an nLog Trace message"); log.Debug("This is an nLog Debug message"); log.Info("This is an nLog Info message"); log.Warn("This is an nLog Warning message"); log.Error("This is an nLog Error message"); log.Fatal("This is an nLog Fatal message"); TelemetryConfiguration.Active.TelemetryChannel.Flush(); Console.WriteLine("Press <enter> to exit>"); Console.ReadLine(); } } }
Code for my sample console application is here.