Viewing Logs in Azure for AppService

269 Views Asked by At

Hi I have simple application where I want to implement the logs so when the error occured I can view the error in a file in Azure.

I read some article they do describe to view the error monitoring. What I actually want to see the error that are added into some file. So when there an error occured in a deployed app, I should be able to go to the log file and read the error or information.

Simple enough I have created a new ASP.NET 6 API which comes wiht the Ilogger. Now cosider if I deploy this app to the Azure and if there is an error how I can see it in a file?

--Above is my original question. After implemenation the proposed solution I am still unable to view the log file or logs any where in the Azure. please see the code and images. I have verified locally in console the information and error are being logged but not showing up in any where in azure.

appsettings.

enter image description here

program.cs

enter image description here

information log and error log

enter image description here

Azure filelog is enabled enter image description here

Folder in kudu not found. enter image description here

WebConfig enter image description here

1

There are 1 best solutions below

4
Harshitha On

When we deploy .NET Core App to Azure App service (using Visual Studio Publish option/GitHub Actions/VS Publish Import Profile), by default Web.config file will be generated in the deployment process.

  • You can check it in the application root directory site/wwwroot.

enter image description here

  • The easiest way to check the logs in a file is by changing the stdoutLogEnabled value to true.

  • Open the web.config file by clicking on edit button.

  • After updating the stdoutLogEnabled value. Run the application. If there are any errors/unable to access the deployed URL, a file with clear error info will be generated in Logfiles folder.

Path: - C:\home\LogFiles

enter image description here

  • New file will be generated after every deployment when you run the application.

enter image description here

Check the Note section in the SOThread to work with web.config locally.

Using AddAzureWebAppDiagnostics:

As mentioned in the MSDoc,

By using AddAzureWebAppDiagnostics, we can write logs to text files in an Azure App Service app's file system

Refer first section in the SOthread which I have posted.

In App Service logs,enable the Application logging and change the Logging level to Error.

enter image description here