I am using Microsoft.ApplicationInsights.NlogTarget to send metrics to application insights from my .Net Framework 4.7 console app with NLog as the logging framework.
All the data gets sent OK, but exceptions that I log with _logger.Error("message", ex) are not set as execptions but instead as trace. This complicates making dashboards and generally findins logs.
Any ideas why this does not log as exception, but instead as trace?
Example code:
try {
string input = "ThisShouldThrow";
JObject jsonObject = JObject.Parse(input);
var activity = jsonObject["DoesnotExist"].ToObject<List<SomeClass>>();
}
catch (Exception ex) {
_logger.Error("Error parsing:", ex);
}
Latest nuget versions installed for Nlog and app insights.
You are calling this method:
Logger.Error(string format, object[] params);
You should be calling this method:
Logger.Error(Exception ex, string format, object[] params);
Try doing it like this (put Exception-object first):
_logger.Error(ex, "Error parsing");