Custom properties are not logged using Application Insights
See original GitHub issueUsing the guidance from the Application Insights logging with .NET an Azure Function (net6.0
and FUNCTIONS_WORKER_RUNTIME
of dotnet-isolated
) does not log custom properties.
Steps to reproduce
The function trigger looks as follows:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using Performance.AuthTokenConfigGenerator.FunctionApp.Error_Responses;
using System;
using System.Collections.Generic;
namespace TokenGenerator.Function
{
public class TokenGeneratorHttpTrigger
{
private readonly ILogger _logger;
public TokenGeneratorHttpTrigger(ILogger<TokenGeneratorHttpTrigger> logger)
{
_logger = logger;
}
[Function(Constants.TokenGeneratorHttpTrigger)]
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get",
Route="TokenGeneratorHttpTrigger/{emailId}")] HttpRequestData req, string emailId, FunctionContext executionContext)
{
try
{
using (_logger.BeginScope(new Dictionary<string, object> { ["MyKey"] = "MyValue" }))
{
_logger.LogError("An example of an Error level message");
}
return new OkObjectResult(emailId);
}
catch (Exception ex)
{
_logger.LogError(ex, "");
return new InternalServerError(ex.Message);
}
}
}
}
Expected results
I should see a custom property logged in application insights associated with the error message An example of an Error level message
Actual results
The custom properties section does not have the custom property I am trying to log:
Additional Information
csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Program.cs
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace Performance.AuthTokenConfigGenerator.FunctionApp
{
public static class Program
{
public static void Main(string[] args)
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
}
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
The Request Telemetry doesn't log custom properties in ...
I want to log custom properties for both request and page view telemetries in Application Insight. I am working in an asp.net webforms...
Read more >I cannot see my custom properties being logged to ...
I cannot see my custom properties being logged to application insights only the message. Does it need additional setup?
Read more >Can you log custom properties with Auto-instrumentation?
Hi, I have a ASP.NET MVC application, I have Application Insights enabled with Auto-Instrumentation and I want to add custom properties on ...
Read more >How to use Application Insights Custom Properties in ...
The telemetry is logged back to an Application Insights instance in your Azure tenant. You can then view all the reported telemetry via...
Read more >Application Insights properties
These system properties control the behavior of the Application Insights application. ... Create time cards and log time through Time Sheet Portal.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Was able to repro; I’ll follow up with the team on next steps and provide an update
Duplicate of #7452