ILogger.LogError 未记录异常详细信息 [英] ILogger.LogError not logging exception details
问题描述
我有一个 Functions 应用程序(2.0 版)并尝试记录异常的堆栈跟踪.
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}");
}
这只会在 App Insights 中记录消息,而不会记录传递的异常对象.
This only logs the message in App Insights but nothing about the exception object passed.
我这样做对吗?
如果我这样做log.LogError(ex, $"Error processing order: {order.Id}", ex)
然后我确实看到了异常消息,但没有看到堆栈跟踪.
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.
推荐答案
除了记录错误外,您还需要使用遥测客户端显式跟踪异常以获取异常详细信息.我在 Web API 2.0 中实现了 ExceptionLogger,以使用跟踪异常方法将异常详细信息发送到 app-insights.
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);
}
这篇关于ILogger.LogError 未记录异常详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!