azure 函数未将异常记录到应用程序洞察中

kri*_*hna 0 azure azure-application-insights

我有具有服务总线主题触发器的 azure 函数。我注意到当函数没有任何异常执行时,所有 tracewriter.loginformation 消息都会正确显示在应用程序洞察中。但是如果发生任何异常,那么晚上会显示 log.information 或 appinsights 中显示 log.error

我的功能在消费计划下运行。我注意到我有 2 个 catch 块。

catch(validation ex) 
{
    log.error;
} 
catch(exception ex) 
{ 
   log.error; 
   throw;
} 
Run Code Online (Sandbox Code Playgroud)

第一个 catch 块中的所有错误都被记录下来,但第二个 catch 块中的所有错误都没有被记录下来。我注释掉了 throw 并且它开始记录到 appinsights .. 请指教。

 <Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net462</TargetFramework>
    <Version>1.6.15</Version>
    <DependsOnNETStandard>netstandard1.5</DependsOnNETStandard>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
    <WarningsAsErrors />
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="1.0.0-beta1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.ServiceBus" Version="2.1.0-beta1" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.0-alpha6" />
    <PackageReference Include="System.IO" Version="4.1.0" />
    <PackageReference Include="System.Runtime" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>
  <ItemGroup>
    <Compile Update="TemplateResource.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>TemplateResource.resx</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <EmbeddedResource Update="TemplateResource.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>TemplateResource.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <Folder Include="Properties\PublishProfiles\" />
  </ItemGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)

Cam*_*amD 5

我有一个类似的问题log.Error(“我的错误消息”)总是导致 Application Insights 中的跟踪而不是异常(这是我想要的)。检查 Application Insights SDK 的源代码后,很明显要在 Application Insights 中获得异常,您必须将异常对象传递到LogError调用中。

例子:

log.Error(ex, "my error message") - will result in Application Insight Exception

log.Error("my error message") - will result in Application Insight Trace
Run Code Online (Sandbox Code Playgroud)