0

我正在使用 Azure Service Fabric 应用程序和 ApplicationInsight 进行日志记录。使用 appsettings.json 进行配置:

{
  "AllowedHosts": "*",
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft": "Debug",
      "Microsoft.ServiceA.PackageB": "Debug"
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Warning",
        "Microsoft": "Debug",
        "Microsoft.ServiceA.PackageB": "Debug"
      },
      "samplingSettings": {
        "isEnabled": true,
        "excludedTypes": "Dependency"
      }
    }
  }
}

在 Startup.cs 中,添加如下连接字符串:

public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
            string InstrumentationKeyEnv = Environment.GetEnvironmentVariable("APPINSIGHTS_CONNECTIONSTRING");
            var options = new ApplicationInsightsServiceOptions { ConnectionString = InstrumentationKeyEnv };
            services.AddApplicationInsightsTelemetry(options: options);
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
            ServicePointManager.DefaultConnectionLimit = 10000;
        }

控制器定义为:

namespace Microsoft.ServiceA.PackageB.Controllers
{       
public class ValuesController : ControllerBase
    {
        private readonly ILogger<ValuesController> _logger;

        public ValuesController(ILogger<ValuesController> logger)
        {
            _logger = logger;
        }
        
        [HttpGet]
        public ActionResult<string> Get()
        {
            _logger.LogDebug($"Debug level logging");
            _logger.LogInformation($"Information level logging");
            _logger.LogWarning($"Warning level logging");
            _logger.LogError($"Error level logging");
            _logger.LogCritical($"Critical level logging");            
            return "";
        }
    }
}

在 ApplicationInsight 中,我只能看到警告、错误和严重日志。没有调试日志。这里有什么问题?

4

0 回答 0