Reputation: 287
I am having a Functions App (version 2.0) and trying to log stack trace of an exception.
try
{
processedOrder = await orderProcessingService.ProcessOrder(order);
}
catch (Exception ex)
{
log.LogError(ex, $"Error processing order: {order.Id}");
}
This only logs the message in App Insights but nothing about the exception object passed.
Am I doing this right?
If I do
log.LogError(ex, $"Error processing order: {order.Id}", ex)
then I do get to see the exception message but not the stack trace.
Upvotes: 10
Views: 4883
Reputation: 82
Apart from logging the error, you need to explicitly track the exception using telemetry client to get the exception details. I implemented ExceptionLogger in web API 2.0 to send the exception details to app-insights using track exception method.
var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
telemetry.TrackException(ex, properties, measurements);
}
Upvotes: 2