I need to see the logs of a .Net application that runs in Azure App Service.
I see many logs in the application source code that I expect to see in Application Insights, but, going to Application Insights > Transaction search (All data last 24 hours) I see only a spike in the exact hour I deployed the application.
The only logs that I see in Application Insights are some traces from Program.cs and the other log in the application's controller and services are not visible.
Here is some minimum code to show what concerns the log configuration in the application and the use of the log in it:
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.WebHost
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseNLog();
... // other stuff
app.Logger.LogInformation("Starting application..."); // Log that I see...
}
A controller example..
public class ProductsController : ControllerBase
{
private readonly ILogger<ProductsController> _logger;
public ProductsController(..., ILogger<ProductsController> logger)
{
... = ...;
_logger = logger;
}
[HttpGet("GuideProducts")]
public async Task<IActionResult> GetGuideProductDesplayAsync(CancellationToken ct = default)
{
_logger.LogInformation("Executing ...."); // Log I DON'T see
...
}
}
I see only the logs from the initial configuration and not during the application usage, I'm running out of ideas on how to troubleshoot this apparently dumb issue.
Check the below steps to get the Logs from Controller in Application Insights.
My
Program.cs
My
Controller.cs
:We need to add
Application Insights
settings inappsettings.json
file.My
appsettings.json
Packages in my
.csproj
fileAccess the URL and execute the Controller Action method.
Traces in Application Insights Transaction Search