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:
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 ?