Azure Functions and Serilog
    • Dark
      Light
    • PDF

    Azure Functions and Serilog

    • Dark
      Light
    • PDF

    Article Summary

    #ServerlessTips - Azure Functions
    Author: Mandar Dharmadhikiri Business & Integration Architecture Manager

    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)

    download 26

    You can then create the logger and register it in the startup class as shown below

    download 27

    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

    download 28

    download 29

    To learn more about dependency injection with Azure Functions you can refer Dependency Injection in Azure Functions

    MicrosoftTeams-image 503


    Was this article helpful?