Type in invocation Details in azure function app is missing but not Timestamp and Message

Aml Abbas 40 Reputation points
2024-04-10T13:56:39.9366667+00:00

I have migrated my Azure function app from the in-process to the isolated worker process.

so I have to add a program.cs with the following code:

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
        services.Configure<KestrelServerOptions>(options =>
        {
            options.AllowSynchronousIO = true;
        });
    })
    .ConfigureLogging((hostingContext, logging) =>
    {
        logging.Services.Configure<LoggerFilterOptions>(options =>
        {
            LoggerFilterRule defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName
                == "Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider");
            if (defaultRule is not null)
            {
                options.Rules.Remove(defaultRule);
            }
        });
        //logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
    })
    .Build();

host.Run();

I can see the timestamp and the message in my invocation details but not the type why?

User's image

User's image

Why I am missing the logLevel?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,481 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Aml Abbas 40 Reputation points
    2024-05-21T13:08:38.88+00:00

    Add this class to ur project

    public class LogLevelTelemetryInitializer : ITelemetryInitializer
    
    {
    
        private const string LogLevelKey = "LogLevel";
    
        public void Initialize(ITelemetry telemetry)
    
        {
    
            if (telemetry is not TraceTelemetry traceTelemetry)
    
            {
    
                return;
    
            }
    
            if (!traceTelemetry.Properties.ContainsKey(LogLevelKey))
    
            {
    
                var level = traceTelemetry.SeverityLevel switch
    
                {
    
                    SeverityLevel.Verbose => "Verbose",
    
                    SeverityLevel.Information => "Information",
    
                    SeverityLevel.Warning => "Warning",
    
                    SeverityLevel.Error => "Error",
    
                    SeverityLevel.Critical => "Critical",
    
                    _ => "Unknown",
    
                };
    
                traceTelemetry.Properties[LogLevelKey] = level;
    
            }
    
        }
    
    }
    

    and add this code to the program.cs

        logging.Services.AddSingleton<ITelemetryInitializer, LogLevelTelemetryInitializer>();
    

    like here

    User's image

    0 comments No comments