Recently, I worked for a client requirement where I implemented Azure Function Logging with Dependency Injection. This article will discuss that functionality.
Azure Function Logging Dependency Injection
You can use the ilogger interface in your startup class. Then, use the “LoggerFactory” class to create the instance for the ilogger interface.
Check out the sample code below to help you implement Azure Function ilogger dependency injection.
public class Startup: FunctionsStartup {
private ILoggerFactory _loggerFactory;
public override void Configure(IFunctionsHostBuilder builder) {
var myconfig = new ConfigurationBuilder().AddJsonFile("local.settings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();
builder.Services.AddLogging();
ConfigureServices(builder);
}
public void ConfigureServices(IFunctionsHostBuilder builder) {
_loggerFactory = new LoggerFactory();
var logger = _loggerFactory.CreateLogger("Startup");
logger.LogInformation("I am in Startup");
//builder implementation goes here
}
} You may also like following the below-related articles
Conclusion
This is how you can implement the Azure Function Logging Dependency Injection. Thanks for reading this article !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
