azure - ILogger.LogError 不记录异常详细信息

标签 azure azure-functions azure-application-insights

我有一个函数应用程序(版本 2.0)并尝试记录异常的堆栈跟踪。

     try
        {
            processedOrder = await orderProcessingService.ProcessOrder(order);
        }
        catch (Exception ex)
        {
            log.LogError(ex, $"Error processing order: {order.Id}");
        }

这只会在 App Insights 中记录消息,但不会记录有关传递的异常对象的信息。

我这样做对吗?

如果我这样做 log.LogError(ex, $"Errorprocessing order: {order.Id}", ex) 然后我确实看到了异常消息,但看不到堆栈跟踪。

最佳答案

除了记录错误之外,您还需要使用遥测客户端显式跟踪异常以获取异常详细信息。我在 Web API 2.0 中实现了 ExceptionLogger,以使用跟踪异常方法将异常详细信息发送到 app-insights。

var telemetry = new TelemetryClient();
    ...
    try
    { ...
    }
    catch (Exception ex)
    {       
       telemetry.TrackException(ex, properties, measurements);
    }

关于azure - ILogger.LogError 不记录异常详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56060604/

相关文章:

c# - 使用 Visual Studio 2019 在本地调试 Azure Function

css - asp.net mvc 模型的 EF Code First 模型更改后,如何在 Azure 中正确更新 SQL 数据库?

azure 权限创建 "service principal"

c# - 无法使用 C# 驱动程序 1.10 连接到 MongoDB 3.0.0

azure - 从 Azure 门户删除未使用的 Application Insights 资源是否安全?

c# - Application Insights Profiler 和 "AWAIT_TIME"

azure - 实时监控 Azure Functions?

node.js - 使用 Azure 存储 Node SDK 创建队列消息时,队列触发的 Azure 函数抛出异常

azure - 我在 azure 存储资源管理器中没有 'azure-webjobs-hosts' 容器,因此我的 azure 函数应用程序将无法运行

azure - 如何在 Azure Function c# 中使用正则表达式路由