LogError(string) 不会在 Application Insights 异常列表中创建条目

问题描述 投票:0回答:0

以下不会在应用洞察异常列表中创建条目:

myLogger.LogError("something is wrong in {location}", "here")

只有以下做:

myLogger.LogError(new Exception("something is wrong here"))
myLogger.LogError(new Exception("something is wrong here"), "something is wrong in {location}", "here")

我想有人可能会称这是一项功能,因为前者记录的是错误而不是异常。我对此的哲学方法是,错误也是异常,但异常并不总是错误(例如,当它被处理时)。

无论如何,后一种语法看起来确实有点奇怪。特别是在最后一种情况下,我需要复制我的消息以利用语义日志记录。

我想知道我是否以错误的方式看待这个。

关于我的实施的更多细节:

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <UserSecretsId>xxxxxxxxxx</UserSecretsId>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <DockerComposeProjectPath>..\docker-compose.dcproj</DockerComposeProjectPath>
  </PropertyGroup>

  <ItemGroup>
     <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.15.0" />
     <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
  </ItemGroup>

builder.Services.AddApplicationInsightsTelemetry(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]);

azure containers azure-application-insights azure-monitoring
© www.soinside.com 2019 - 2024. All rights reserved.