I have developed an ASP.NET Core 6 MVC web app. During development I use loggers at controllers or services like this:
public Result MyService()
{
_logger.LogInfomation("MyService!");
// Service's code.
}
However, after deploying to Azure App Service, I cannot find a place to observe these logs. I have tried setting App service logs
and looking at Log stream
but it doesn't have the information I need.
In the deployed Azure App Service, you can check the logs in Log Stream / Application Insights or even in the KUDU Debug Console.
If you want to check the Information logs in Log Stream, configure AddAzureWebAppDiagnostics
in Program.cs
file.
Install the Microsoft.Extensions.Logging.AzureAppServices
latest NuGet Package.
My Program.cs
file:
builder.Services.AddLogging(logs =>
{
logs.AddConsole();
logs.AddAzureWebAppDiagnostics();
});
HomeController.cs
file:
public IActionResult Index()
{
_logger.LogInformation("MyService!");
_logger.LogInformation("Logs from Controller");
return View();
}
LogStream:
Refer my SO Thread to configure Application Insights from Code.