0

I have the following Startup class for azure function:

public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            //some code
        }
    }

How could I inject here Microsoft.Extensions.Logging.AzureAppServices provider and use AddAzureWebAppDiagnostics? something like:

.ConfigureLogging(logging => logging.AddAzureWebAppDiagnostics())

I use .Net Core 3.1

SimonD
  • 1,441
  • 2
  • 18
  • 30

1 Answers1

0

Please use the code below in your Startup class:

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

[assembly: FunctionsStartup(typeof(FunctionApp9.Startup))]
namespace FunctionApp9
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            ConfigureServices(builder.Services).BuildServiceProvider(true);
        }

        private IServiceCollection ConfigureServices(IServiceCollection services)
        {
            services.AddLogging(logging =>
            {
                logging.AddAzureWebAppDiagnostics();
            });

            return services;
        }

    }
}
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • Ivan Yang thanks for your answer. Do you know whether this should write to azure portal log stream console in app service? – SimonD Jun 19 '20 at 13:06
  • I mean function -> Monitor -> Logs. Somehow output there is not complete in comparison to AppInsights logs. – SimonD Jun 19 '20 at 13:53
  • @SimonD, not sure, but I think application insights should collect more since it's more powerful. And we always recommend to use application insights for azure function:). – Ivan Glasenberg Jun 22 '20 at 01:52
  • And it helps, could you please accept it as answer? Thanks. – Ivan Glasenberg Jun 22 '20 at 06:21