天青函数不会将异常记录到应用程序见解

时间:2018-07-19 19:59:14

标签: azure azure-application-insights

我有一个具有服务总线主题触发器的Azure函数。我注意到当函数无任何异常执行时,所有tracewriter.loginformation消息都会正确显示在应用程序见解中。但是如果发生任何异常,则appinsights中将显示夜间的log.information或log.error

我的功能正在消耗计划下运行。我注意到我有2个接球区。

catch(validation ex) 
{
    log.error;
} 
catch(exception ex) 
{ 
   log.error; 
   throw;
} 

第一个catch块中的所有错误均未记录,但第二个catch块中的所有错误均未记录。我注释掉了throw,它开始记录到appinsights。.但是我需要throw进行死信。请告知。

 <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>

2 个答案:

答案 0 :(得分:1)

我有一个类似的问题,因为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

答案 1 :(得分:0)

我试图用您的版本对其进行复制,但它仍然对我有用。

try
{
    if (new Random().NextDouble() > 0.5)
    {
        throw new ArgumentNullException("null");
    }

    throw new Exception("some exception");
}
catch (ArgumentNullException)
{
    log.Error("null");
}
catch (Exception e)
{
    log.Error("some exception");
    throw;
}

我在Application Insights中看到“ null”和“某些异常”。

enter image description here

顺便说一句,已经有稳定的Microsoft.NET.Sdk.Functions 1.0.14,自1.0.0-alpha6起,它应该包含许多修复程序。

相关问题