0

I am facing a problem with logging information from other classes' methods while running my azure timer trigger locally.

I have the following timer trigger function :

public class ExpServiceFuncApp
{

    [FunctionName("ExpServiceFuncApp")]
    public static void Run([TimerTrigger("0 */1 * * * *")] TimerInfo myTimer, ILogger log)
    {
        try
        {
            IServiceCollection services = new ServiceCollection();

            services.AddLogging(builder =>
            {
                builder.AddApplicationInsights(Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY", EnvironmentVariableTarget.Process));
                builder.SetMinimumLevel(LogLevel.Debug);
            })

            .AddSingleton<IDataRec, DataRec.DataRec>()
            .AddSingleton<IDataProc, DataProc.DataProc>()
            .AddSingleton<IDClient, KustoDClient>()
            .AddSingleton<IAzureBlobClient, AzureBlobClient>()
            .AddSingleton<IAzureKustoClient, AzureKustoClient>()
            .AddSingleton<IQueriesSettings, QueriesSettings>()
            .AddSingleton<IServiceSettings, ServiceSettings>()
            .AddTransient<IRawData, RawData>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();


            log?.LogInformation("Initiate.");
            var dataProc = serviceProvider.GetRequiredService<IDataProc>();

            log?.LogInformation("Start Data Process.");
            dataProc.Start();

        }
        catch (Exception ex)
        {

        }

    }
}

In this Azure Function that I have created I also have other classes which are being used and which contain logs which should be displayed. One example of those classes is the following:

public class KustoDataClientBase
{
    protected static async Task<IRawData> GetDataAsync(IAzureKustoClient azureKustoClient, string database, CancellationToken cancellationToken, ILogger logger)
    {
        var stopwatch = new Stopwatch();
        logger?.LogInformation($"Get data from database '{database}'");

        stopwatch.Start();

        {
            //Some code;
        }

        stopwatch.Stop();

        logger?.LogInformation($"Executing queries took {stopwatch.Elapsed:g});
    }
}

The problem here is when I run this functionapp locally I get the following results:

enter image description here

As you can see, I am only seeing the logs in the ExpServiceFunApp class but not in the remaining classes. I have like 7 other logs that should also appear .

Can someone please explain what is going on here. Not that I am running locally and this is not yet published on Azure. Should I remove something from the code in the timer trigger ? What should I do in order to see allow all logs from the other classes also appear ?

Richard Deeming
  • 29,830
  • 10
  • 79
  • 151
Noobie2021
  • 281
  • 4
  • 23
  • Is there a particular reason why you are setting up your DI container in your function rather on startup of your app? – Exitare Dec 08 '21 at 19:17
  • @Exitare The thing is that the code was already implemented that way. This was basically a console application so we didn't have any startup class. This DI container was in the program.cs file main function in the console application. So what I did is that I simply copied the code inside the program.cs file and placed it in the run method of timer trigger. – Noobie2021 Dec 08 '21 at 19:40
  • @Exitare Can you please tell me how is it possible to do it using DI if I want to create the Startup Class ? – Noobie2021 Dec 09 '21 at 17:51

0 Answers0