How to: Configure Azure Web App Logging With .NET 5

Chris J.
The Startup
Published in
2 min readNov 15, 2020

--

dotnet-bot © .NET Foundation

Azure Web App Diagnostics are a set of tools provided by Microsoft which purpose is to provide logging capabilities for ASP.NET Apps deployed to Azure. The logs are typically stored in the filesystem of the Azure App Service.

While developing a Web App or an API, this can be very useful in order to debug it.

Prior to ASP.NET Core 2.1, logging on Azure was pretty straightforward. The logs wrote by an Microsoft.Extensions.Logging.ILogger were defaulted to be logged in a file accessible via Azure.

But starting with .NET 5 (and maybe .NET Core 3.1), logging configuration has to be more explicit in order to enable it.

The goal of this article is to guide you through configuring Azure logging with .NET 5, and then to show you where to find them quickly.

Step 1 : Enable the filesystem logs on Azure Portal

In order to enable the logs, just go to your app’s settings and scroll until you see App Service Logs.

The most important setting to enable is the Application Logging (Filesystem). Then put the Verbose level to be sure to not miss any log.

Just follow the above figure:

Step 2 : Write the configuration code

From .NET Core 3.1 to .NET 5, the logging configuration code takes place inside the Program class, right while configuring the web host.

First, install the package Microsoft.Extensions.Logging.AzureAppServicesusing this nuget.

Then, add the following code while you configure your web host:

Configuring Azure Logging

Step 3 : Eventually, log !

From a controller, or anywhere else, acquire the logger via IoC and start logging.

Example of logging

Step 4 : See the logs quickly

On the Azure portal, there is a log stash where you can stream the logs right from your web browser. It is called the Log stream.

Just navigate to the Log stream settings pane, and admire your very own logs !

Conclusion

Et voilà ! You successfully added logs to your Azure App service.

You can learn more about logging with .NET 5 here.

For example, you can configure your logs with file-based app-settings, instead of using code like we just did.

Have a pleasant day ! 😊

--

--

Chris J.
The Startup

I’m a Tech Enthusiast and a passionate Software Engineer. I write about consumer tech and IT Engineering.