可以采用以下方法解决此问题:
确保已经在应用或容器中安装了Application Insights SDK。
可以尝试使用以下API手动写入Application Insights:
telemetryClient.trackMetric("Metric Name", metricValue);
telemetryClient.trackTrace("Trace Message");
telemetryClient.trackEvent("Event Name");
当然,需要在应用中引用Application Insights SDK。
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TelemetryConfiguration configuration)
{
// other configuration code
// Enable Application Insights
app.UseApplicationInsightsRequestTelemetry();
app.UseApplicationInsightsExceptionTelemetry();
// Configure application insights
configuration.InstrumentationKey = "";
}
此代码可确保应用能够将请求和异常写入Application Insights。
以上4种方法的任何一种都可以解决AKS无法将日志写入Application Insights的问题。