gpt4 book ai didi

azure - 部署在 Azure 上时,应用程序见解中没有数据

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

我有一个 .net core 2 MVC Web 应用程序,它使用 Azure 上的应用程序见解。我还配置了 nlog 以通过应用程序洞察进行跟踪。在我的电脑上一切正常,因为我在 azure 上发现了异常和跟踪,但是当我部署应用程序并在 azure 上使用它时,它不会在应用程序洞察中生成任何事件(我只发现了日志文件)。

因此,我尝试在 Controller 中创建 TelemetryClient 实例,它甚至在已部署的实例中也能正常工作:

TelemetryClient tc = new TelemetryClient()
{
InstrumentationKey = "11111111-2222-3333-4444-555555555555"
};
tc.Context.User.Id = Environment.MachineName;
tc.Context.Session.Id = "session_id";
tc.Context.Device.OperatingSystem = Environment.OSVersion.ToString();
tc.TrackTrace("Privacy page says hello with TelemetryClient");

以下是我的项目的片段:

appsettings.json

{
"ApplicationInsights": {
"InstrumentationKey": "11111111-2222-3333-4444-555555555555"
}
}

appsettings.Staging.json

{
"ConnectionStrings": {
"DefaultConnection": "Server=tcp:dom.database.windows.net,1433;Initial Catalog=dom;Persist Security Info=False;User ID=user;Password=pass;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
},

"AllowedHosts": "*",

"Logging": {
"LogLevel": {
"Default": "Trace",
"System": "Information",
"Microsoft": "Information"
}
}
}

我在 VS 和 Azure(暂存)上定义了相同的 ASPNETCORE_ENVIRONMENT 值,以确保加载相同的应用程序设置并部署所有文件。

我是这样加载配置的

var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environmentName}.json", optional: true)
.AddEnvironmentVariables()
.Build();

CreateWebHostBuilder是这个

public static IWebHostBuilder CreateWebHostBuilder(string[] args, IConfiguration config) =>
WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext) =>
{
//config.AddJsonFile("appsettings.json");
})
.UseStartup<Startup>()
.ConfigureLogging(
logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseApplicationInsights() // Enable Application Insights
.UseNLog();

nlog.config 包含

  <extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<targets>
<target type="ApplicationInsightsTarget" name="aiTarget" />
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
</targets>
<rules>
<logger name="*" minlevel="Warn" writeTo="aiTarget" />
<logger name="*" minlevel="Warn" writeTo="f" />
</rules>

在我看来,配置或 InstrumentationKey 有问题,但我不知道如何检查它。

有什么想法,或者...有什么方法可以知道如何配置应用程序洞察库,以便找到一些有用的信息来解决问题?我尝试过远程调试,但我不知道要检查什么。

最佳答案

根据您的描述,我认为您在 Azure 门户 -> 您的 Web 应用程序 -> 配置 -> 应用程序设置中设置了另一个应用程序见解 key 。

请检查您是否执行了此操作:

enter image description here

如果 key 在那里,您需要将其删除。或者将这行代码 AddEnvironmentVariables() 放在 AddJsonFile() 之前,如下所示:

var configuration = new ConfigurationBuilder()
.AddEnvironmentVariables() //put this before AddJsonFile()
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{environmentName}.json", optional: true)
.Build();

如果您有更多问题,请告诉我。

关于azure - 部署在 Azure 上时,应用程序见解中没有数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56097743/

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