The Azure App Service web apps provide diagnostic functionality for logging information from both the web server and the web application. It logically separates this into web server diagnostics and application diagnostics. When you enable this feature in Azure, you can specify a log data storage account and container for each of these to save them .
Full demo :Â
Â
Â
Enable the filesystem logs on Azure Portal
In order to activate the logs here , after you create the web application ,we need to go to Monitoring and go to App Service logs and we need to activate Application Logging (Filesystem) and change Web server logging to File System .
Add the configuration code
First of all ,we need to install the package : Microsoft.Extensions.Logging.AzureAppServices from this link .
Next we are going to do some changes inside the Program.cs
public class Program { public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); } public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder .UseStartup<Startup>() .ConfigureLogging(logging => { logging.ClearProviders(); logging.AddConsole(); logging.AddAzureWebAppDiagnostics(); }); }); }
Â
Add Logs
Inside our controllers , we will find already the logs implemented ,all we need to do is to add few lines depends of the type of the logs that you want to write :
_logger.LogInformation("LogInformation WeatherForecast"); _logger.LogWarning("LogWarning WeatherForecast"); _logger.LogDebug("LogDebug WeatherForecast");
Â
Watch our logs
Â
Well , that was our quick demo about the logs on azure ,to read more about it on Microsoft website link