I want to achieve the following:
- Have custom log statements in my ASP.NET Core web service application.
- Deploy my application to Azure (in my case using Pulumi).
- Call the webservice so it triggers the logging code.
- Read the logged messages, either programmatically or via the Azure browser-based GUI.
I am targeting .NET 5.0.
In my code I do something like this:
public class MyController : ControllerBase
{
private readonly ILogger<MyController> _logger;
public MyController(ILogger<MyController> logger) => _logger = logger;
public async Task<ActionResult<something>> DoStuff()
{
_logger.LogInformation("Hello, World!");
...
}
}
My Pulumi code contains this:
var app = new AppService(
"kmsApp",
new AppServiceArgs
{
Logs = new AppServiceLogsArgs
{
ApplicationLogs = new AppServiceLogsApplicationLogsArgs { FileSystemLevel = "Error" },
DetailedErrorMessagesEnabled = true,
FailedRequestTracingEnabled = true,
HttpLogs = new AppServiceLogsHttpLogsArgs
{
FileSystem = new AppServiceLogsHttpLogsFileSystemArgs { RetentionInDays = 1, RetentionInMb = 35 }
}
}
},
...);
With the above, when I am running my application in debug mode in Visual Studio, I can see the log messages in the Output pane. So the logging code definitely gets triggered. But when I deploy my application to Azure, I don't know how to get the log messages, and I find the Azure GUI confusing.
What I am struggling with is this:
- What configuration do I need to do in my code - e.g. NuGet packages or stuff in my
Program
andStartup
classes? - What configuration do I need to do in Azure?
- Where in the Azure browser-based GUI do I go to see these log messages?
- How can I fetch these logs programmatically (either via Pulumi or the raw Azure API)?
I have looked for documentation, of course, but I find the documentation labyrinthine. Most of it seems to be about diagnostics such as response time. I just want to view my own custom log messages from my code...
Posts like this one give some hints, but after reading the thread it is still nebulous to me how to read the logs: ASP.NET Core trace logging on Azure with Application Insights
There probably exists good documentation and guides. Please help me find them.
Thanks in advance!