/ notes / azfunctions
⇒ This is just a collection of notes, not a structured or comprehensive document. ⇐

Migrate Azure Function from NET 8 in-process to NET 8 isolated

The migration from NET 8 in-process to NET 8 isolated is not simple and straightforward as migrating from NET 6 in-process to NET 8 in-process. Below I summarize the steps I normally follow with some additional notes and piece of code. Official Microsoft documentation here.

Main steps on the project

Considering a Function project already on NET 8 in-process

Strange error

You might find yourself stuck with errors like the one below. Sometime this error cover other compile errors. In such a case, check the compile errors in the Output window / Build of Visual Studio. Then, solve all the other compile errors and this will disappear. Some restart of VS 2022 are also usefull. Sometimes an explicit delete of bin and obj folders can help.

MSB3202 The project file "C:\.....\FunctApp\obj\Debug\net8.0\WorkerExtensions\WorkerExtensions.csproj" was not found. FunctApp File: C:\Users\.....\.nuget\packages\microsoft.azure.functions.worker.sdk\2.0.4\build\Microsoft.Azure.Functions.Worker.Sdk.targets

UPDATE: solved in Microsoft.Azure.Functions.Worker.Sdk version 2.0.5

</small>

Application Insights configuration

[TODO: add details…]

See example below.

Program.cs example

using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

// ...
// ...

public static void Main(string[] args)
{
    var host = new HostBuilder()
        .ConfigureFunctionsWebApplication()
        .ConfigureServices(services =>
        {
            services.AddApplicationInsightsTelemetryWorkerService();
            services.ConfigureFunctionsApplicationInsights();
        })
        .ConfigureLogging(logging =>
        {
            // By default, application insights logger starts with this filter rule (level=Warning);
            //    {ProviderName: 'Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider', CategoryName: '', LogLevel: 'Warning', Filter: ''}

            logging.Services.Configure<LoggerFilterOptions>(options =>
            {
                LoggerFilterRule? defaultRule = options.Rules.FirstOrDefault(rule => rule.ProviderName == typeof(Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider).FullName);
                if (defaultRule is not null)
                {
                    options.Rules.Remove(defaultRule);
                }
            });

            // Note: adding filter is easy. Removing requires more code.
            //    logging.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>(null, LogLevel.Debug);
        })
        .Build();

    var logger = host.Services.GetRequiredService<ILogger<Program>>();
    logger.LogInformation("*****************************************");
    logger.LogInformation("Starting Function APP...");            

    host.Run();
}



Main steps for deploying to Azure

Considering a function app already running as NET 8 in-process





Misc

Logging on Application Insights : (

What a mess!

https://github.com/Azure/azure-functions-dotnet-worker/issues/2059