In an Azure function the run method creates an ILogger which in my main class I can use to log errors and information, however, I am using helper classes to run my Graph API and Cosmos DB queries.
What is the best way to log errors and information in the separate classes, should I be passing the log in all my classes or methods? or is there a better way to make the ILogger available to all classes at runtime?
public class AzureFunction
{
public Task Run([TimerTrigger("0 0 1 * * *")] TimerInfo myTimer, ILogger log)
{
log.LogInformation("This message logs correctly");
GraphHelper graphHelper = new GraphHelper();
graphHelper.GetGraphData();
}
}
public class GraphHelper
{
public void GetGraphData()
{
try
{
asyncTask()
}
catch (Exception ex)
{
log.LogInformation($"{ex.Message} - How can I log this without passing ILogger to every class or method?");
}
}
}