gpt4 book ai didi

azure - Azure 应用程序见解中存在大量 n/a 关键跟踪消息

转载 作者:行者123 更新时间:2023-12-03 03:25:02 24 4
gpt4 key购买 nike

我在 Azure 中托管了 dotnet core Web 应用程序,并使用应用程序洞察进行日志记录。我发现我有异常数量的 n/a 关键跟踪消息,例如 1 分钟内大约 11k。有人在应用洞察中遇到过这个问题吗? enter image description here

图书馆:

  • Microsoft.ApplicationInsights.AspNetCore 版本=2.15.0
  • Microsoft.ApplicationInsights.DependencyCollector 版本=2.15.0
  • Microsoft.ApplicationInsights.DiagnosticSourceListener 版本=2.15.0
  • Microsoft.ApplicationInsights.EventSourceListener 版本=2.15.0
  • Microsoft.ApplicationInsights.TraceListener 版本=2.15.0
  • Microsoft.ApplicationInsights.WindowsServer 版本=2.15.0
  • Microsoft.AspNetCore.Hosting 版本=2.2.7

dotnet 运行时:netcoreapp3.1

我已在下面配置了应用程序见解。

public static IWebHostBuilder UseLoggingWithAppInsights(this IWebHostBuilder builder)
{
builder.ConfigureServices((context, services) =>
{
services.AddApplicationInsightsTelemetry(applicationInsightsInstrumentKey);
});

var provider = services.BuildServiceProvider();
IWebHostEnvironment host = provider.GetService<IWebHostEnvironment>();
IHttpContextAccessor context = provider.GetService<IHttpContextAccessor>();

TelemetryConfiguration.Active.EnableTelemetry(applicationInsightsInstrumentKey, appName, telemetryDetails, telemetrySettings, context, host);

TelemetryConfiguration config = provider.GetService<TelemetryConfiguration>() ?? TelemetryConfiguration.CreateDefault();

TelemetryConfiguration.Active.FireTraceToSeeIfActive();
config.FireTraceToSeeIfActive();

builder.ConfigureServices((context, services) =>
{
var instrumentationKey = context.Configuration.GetValue<string>("ApplicationInsights:InstrumentationKey");

if (string.IsNullOrWhiteSpace(TelemetryConfiguration.Active.InstrumentationKey)
|| TelemetryConfiguration.Active.InstrumentationKey != instrumentationKey)
{
TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
}

var provider = services.BuildServiceProvider();
Util.StaticApplicationLogging.LoggerFactory = provider.GetRequiredService<ILoggerFactory>();
});

builder.ConfigureLogging((builderContext, loggingBuilder) =>
{
loggingBuilder.AddConfiguration(builderContext.Configuration.GetSection("Logging"));
});

return builder;
}

最佳答案

Lots of n/a critical trace message in Azure application insights

此问题的原因可能是 appsettings.json 文件中的配置不正确。

并且您使用的代码不推荐在.NET Core应用程序中使用。

 TelemetryConfiguration.Active.EnableTelemetry(applicationInsightsInstrumentKey, appName, telemetryDetails, telemetrySettings, context, host);

enter image description here

  • 降低消息的严重性级别,这可以通过仅设置所需的日志级别来完成。

我的初始 appsettings.json 文件。

{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ApplicationInsights": {
"ConnectionString": "AppInsightsConnString"
}
}
  • 通过上述appsettings,仅显示错误严重警告消息。
  • 要记录信息调试异常消息,必须在appsettings.json文件中进行一些更改.

appsettings.json 文件:

{
"Logging": {
"ApplicationInsights": {
"LogLevel": {
"Default": "Debug",
"Microsoft": "Error"
}
},
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=a******;IngestionEndpoint=https://*******8.in.applicationinsights.azure.com/;LiveEndpoint=https://*******.livediagnostics.monitor.azure.com/"
}
}
  • 确保所有软件包都是最新且已更新。

.csproj 文件:

<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DiagnosticSourceListener" Version="2.15.0" />
<PackageReference Include="Microsoft.ApplicationInsights.EventSourceListener" Version="2.15.0" />
<PackageReference Include="Microsoft.ApplicationInsights.TraceListener" Version="2.15.0" />
<PackageReference Include="Microsoft.ApplicationInsights.WindowsServer" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
</ItemGroup>
</Project>

Startup.cs 文件:

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace WebApplication1
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
services.AddControllersWithViews();
}

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}

应用程序洞察跟踪:

enter image description here

enter image description here

关于azure - Azure 应用程序见解中存在大量 n/a 关键跟踪消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75883838/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com