skip to Main Content

I have an ASP.NET Core application running as Azure App Service. Azure Application Insights is enabled (I followed these instructions). The problem is my instance of Azure Insights on Azure Portal isn’t showing any useful data except for Live Metrics (see the screenshot). As you can see there are multiple requests and custom events on the screenshot.

However, when I open Transaction search it shows nothing (see the screenshot).
Events page is empty as well (see the screenshot).

So far I double-checked an InstrumentKey. Also I tried to use ConnectionString instead of InstrumentKey, but it didn’t help.

My app is running on .NET Core 3.1. I installed the latest version of Microsoft.ApplicationInsights.AspNetCore package which is 2.19.0.

Here is how logging is configured in Program.cs:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .ConfigureLogging(builder =>
            {
                builder.AddFilter<ApplicationInsightsLoggerProvider>("", LogLevel.Information);
            });

And below is code from Startup.cs:

services.AddApplicationInsightsTelemetry(new ApplicationInsightsServiceOptions 
        {
            ConnectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING")
        });

LogLevel is also configured in appsettings.json:

"Logging": {
"LogLevel": {
  "Default": "Warning"
},
"ApplicationInsights": {
  "LogLevel": {
    "Default": "Information"
  }
}

Update:
My Admin who has more permissions can see all data, including events, performance operations etc. So I suppose there’s something to do with permissions. Though it’s strange that I’m not seeing any warning messages. The Admin assigned me more roles (see the screenshot), but it didn’t make any difference.

I would appreciate any help on this issue!

2

Answers


  1. Chosen as BEST ANSWER

    After tearing almost all hair off my head I finally solved the issue! Turned out the instance of Azure Application Insights was linked to a Log Analytic Workspace that belonged to a Resource Group to which I didn't have access. So logs were stored properly, but I didn't have permission to read them. My admin solved the issue by creating a new instance of Azure Application Insights which was linked to a Log Analytic Workspace within my Resource Group. To anyone who isn't familiar with Log Analytic Workspace - it can be specified when you create a new instance of Azure Application Insights (see the screen).

    Thanks everyone for trying to help me!

    UPDATE: As Jonathan L. mentioned in the comments, instead of creating a new Application Insights instance, one can just change Workspace in Properties.


  2. I have tried the same and can able to see the logs inside portal .

    As Peter Bons suggested make sure that you are using ILogger in your controller .

    Here are the steps i have followed .

    • I have download an sample project from GitHub and after extract open project in Visual studio and configure with Application insight telemetry . Updated latest Microsoft.ApplicationInsights.AspNetCore to 2.19.0

    enter image description here

    And added instrumentation key in my appsettings.json which copied from Azure portal>Application insight(my applnsight)>overview.

    {
      "Logging": {
        "ApplicationInsights": {
          "LogLevel": {
            "Default": "Debug",
            "Microsoft": "Error"
          }
        },
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AllowedHosts": "*",
      "ApplicationInsights": {
        "InstrumentationKey": "mykey",
        "ConnectionString": "InstrumentationKey=6xxxxxx-xxxxx-xxxx-xxxx-0000000xxxxxxxx.in.applicationinsights.azure.com/"
      }
    }
    
    • Ilogger configuration in my controller.cs
    namespace ApplicationInsightsTutorial.Controllers
    {
        [ApiController]
        [Route("[controller]")]
        public class WeatherForecastController : ControllerBase
        {
            private static readonly string[] Summaries = new[]
            {
                "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
            };
    
            private readonly ILogger<WeatherForecastController> _logger;
    
            public WeatherForecastController(ILogger<WeatherForecastController> logger)
            {
                _logger = logger;
            }
    
            [HttpGet]
            public IEnumerable<WeatherForecast> Get()
            {
    
                var iteracion = 4;
    
                _logger.LogDebug($"Debug {iteracion}");
                _logger.LogInformation($"Information {iteracion}");
                _logger.LogWarning($"Warning {iteracion}");
                _logger.LogError($"Error {iteracion}");
                _logger.LogCritical($"Critical {iteracion}");
    
                try
                {
                    throw new NotImplementedException();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                }
    
                var rng = new Random();
                return Enumerable.Range(1, 5).Select(index => new WeatherForecast
                {
                    Date = DateTime.Now.AddDays(index),
                    TemperatureC = rng.Next(-20, 55),
                    Summary = Summaries[rng.Next(Summaries.Length)]
                })
                .ToArray();
            }
        }
    }
    

    In startup.cs added

     public void ConfigureServices(IServiceCollection services)
            {
                services.AddControllers();
                services.AddApplicationInsightsTelemetry();//telemetry added
            }
    

    After all that above configuration run the application and navigate to Azure portal to check the logs .

    enter image description here

    Make sure that you have provided the log information which you want to check as example in my controller.cs .

    from the logs we can see the exceptions/errors with line of code as well .
    Here are some screenshot for reference:
    enter image description here

    enter image description here

    enter image description here

    For more information please refer this SO Thread .

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search