如何解决监控在 Azure Kubernetes 服务 (AKS) 上运行的 C# 容器
我有一个在 AKS 上运行的 DotNet Core docker 容器,它需要处理来自队列的消息并将遥测数据发送到 Application Insights 或 Log Analytics。我有一个运行良好的 ASP.NetCore 应用程序,但我在控制台应用程序中看不到任何日志。 这是我启动应用程序的方式:
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((hostingContext,config) =>
{
config.AddEnvironmentVariables();
})
.ConfigureLogging((hostBuilderContext,loggingBuilder) =>
{
loggingBuilder.AddConsole(consoleLoggerOptions => consoleLoggerOptions.TimestampFormat = "[HH:mm:ss]");
})
.ConfigureServices(services =>
{
services.AddHostedService<RunsQueueProcessor>();
services.AddApplicationInsightsTelemetryWorkerService();
services.AddApplicationInsightsKubernetesEnricher();
});
这是我的 applicationsettings.json
{
"Logging": {
"IncludeScopes": true,"LogLevel": {
"Default": "Information","System": "Information","Microsoft": "Information"
}
},"ApplicationInsights": {
"InstrumentationKey": ".....","LogLevel": {
"Default": "Information"
}
},"ServiceBus": {
"ConnectionString": "..."
},"ConnectionStrings": {
"DatabaseContext": "...",}
向这些类型的应用程序添加监控的正确方法是什么?
[编辑]
这是我的部署 yaml 文件。我从 Azure DevOps 管道运行它
apiVersion: apps/v1
kind: Deployment
metadata:
name: <project>-deployment
spec:
replicas: 1
selector:
matchLabels:
run: <project>-worker
template:
metadata:
labels:
run: <project>-worker
spec:
containers:
- name: <container>
image: <acr>.azurecr.io/<container>:{tag}
这是我的部署任务。我正在做 -f 并传递上一个文件
- task: Kubernetes@1
inputs:
connectionType: 'Azure Resource Manager'
azureSubscriptionEndpoint: '<>'
azureResourceGroup: '<azure-rg>'
kubernetesCluster: '<aks-cluster>'
useClusterAdmin: true
command: 'apply'
arguments: '-f src/<...>/deployment.yaml'
secretType: 'dockerRegistry'
containerRegistryType: 'Azure Container Registry'
解决方法
要查看信息级别消息,您应该更改 applicationsettings.json 中的设置:
将 ApplicationInsights
部分放入 Logging
部分。如下图:
{
"Logging": {
"LogLevel": {
"Default": "Information","Microsoft": "Information","Microsoft.Hosting.Lifetime": "Information"
},"ApplicationInsights": {
"LogLevel": {
"Default": "Information","System": "Information","Microsoft": "Information"
}
}
},//other settings.
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。