DEV Community

Tauseef
Tauseef

Posted on • Updated on

Azure Functions logging with log levels

Overview of My Submission

Logging with log-levels and to different sink targets in Azure Functions

Problem

In most Server-less boilerplate template, generally a log context is provided which logs to default log service of the respective Cloud provider i.e. Azure Application metric.

However, they do not provide the ability to log messages with different log levels which is really necessary for large distributed micro-service based systems where-in you need to drill down to a particular warning or debug message.
Without a log-level, it becomes tedious to filter out the types of message that really interests us.

Use Serilog in your Azure Functions

There are lot of readily available libraries which provide a means to perform structured event logging with context and push event message in custom formatted template. We will explore one such open-source library called Serilog.

Serilog provides a mechanism to perform structured logging and way to switch between different log-levels. It also supports a bunch of different target sinks.

Checkout the sample code in the github link. Once up and running trigger your function app with a query paramater and see Serilog in action.

Check the App Insights Logs to view the logs in real-time. Notice how the logs are colored based on the log severity i.e. warning, info or error etc.

Submission Category:

Computing Captains

Link to Code on GitHub

github

In-Action

Image description

Top comments (0)