如何从托管在 Linux systemd 服务中的 ASP.NET Core 应用程序使用 Azure Application Insights

问题描述 投票:0回答:0

我创建了一个 ASP.NET Core Web API,它使用在 Linux 上运行的 Application Insights。

必须进行哪些设置才能让我的应用程序也可以将托管在 Linux 服务中的遥测数据发送到 Application Insights?

服务

[Unit]
Description=DEPRAG GraphViewer CLOUD API TEST

[Service]
Type=notify
ExecStart=/srv/www/test/WebApplication1
WorkingDirectory=/srv/www/test/
KillMode=process
Environment=ASPNETCORE_ENVIRONMENT=Production

[Install]
WantedBy=multi-user.target

Programm.cs

var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSystemd();
// Add services to the container.
builder.Services.AddApplicationInsightsTelemetry();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

appsettings.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "InstrumentationKey": "THE_INSTRUMENTATION_KEY",
    "ConnectionString": "THE_CONNECTION_STRING"
  }
}

如果我直接通过 bash 启动应用程序,则遥测数据的传输有效。

我在 Azure 门户中看到实时指标数据。

如果我在 systemd 服务中托管应用程序,则遥测数据的传输不起作用。

我在 Azure 门户中看不到任何实时指标数据。 以下消息显示在实时指标菜单项中: 不可用:无法连接到您的应用程序

linux asp.net-core azure-application-insights systemd
© www.soinside.com 2019 - 2024. All rights reserved.