Home > Mobile >  Azure AppInsight Log Information not working
Azure AppInsight Log Information not working

Time:12-09

In Asp.net Core version 3.1 I have tried to log LogInformation to Application Insights, but it is not logging in App Insight.

private readonly ILogger<LogService> _logger;

public LogService(IOptions<LogConfig> logConfig, ILogger<LogService> logger)
 {
    _logConfig = logConfig.Value;

    _logger = logger;
 }
_logger.LogInformation("Parameters: {Log Info}", _logConfig.IsLogEnabled);

But Logging Error is working

_logger.LogError(e, "Parameters: {HttpMethod}, {ErrorCode}", logEntry.HttpMethod, logEntry.ErrorCode);

Using package Microsoft.ApplicationInsights.AspNetCore version 2.21.0

In Startup.cs

services.AddApplicationInsightsTelemetry();

In appSettings.Development.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    }
  },
  "ApplicationInsights": {
    "LogLevel": {
      "Default": "Information"
    },
    "ConnectionString": "secret"
  }
}

CodePudding user response:

You are setting the AI loglevel at the incorrect level. It should be like this:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information"
      }
    }
  },
  "ApplicationInsights": {
    "ConnectionString": "secret"
  }
}
  • Related