Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ILogger.LogError not logging exception details

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.

like image 656
Manvir Singh Avatar asked May 09 '19 13:05

Manvir Singh


1 Answers

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);
    }
like image 50
Jithesh Balakrishnan Avatar answered Oct 02 '22 12:10

Jithesh Balakrishnan