- Print
- DarkLight
- PDF
Azure Functions and Serilog
- Print
- DarkLight
- PDF
The .NET runtime based Azure Functions provides an implementation of ILogger connected to application insights which supports structured logging.
Azure Functions also provide the ability to inject other logger implementations through the use of ILoggerProvider. One such provider which is abundantly used is Serilog which supports structured logging across various sinks like console, file, application insights etc.
To use Serilog in your project you will have to install the necessary nuget packages as shown below (This sample shows Console and File sinks)
You can then create the logger and register it in the startup class as shown below
More configuration options are available in serilog wiki.
You can then use the standard way of logging in the azure function using the ILogger implementation highlighted above.
The new implementation produces logs on console and File as shown in following screenshot
To learn more about dependency injection with Azure Functions you can refer Dependency Injection in Azure Functions