Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
415 views
in Technique[技术] by (71.8m points)

.net core - Monitoring a C# container running on Azure Kubernetes Service (AKS)

I have a DotNet Core docker container running on AKS that needs to process messages from a queue and send telemetry to Application Insights or Log Analytics. I have a ASP.NetCore app that works fine, but I cannot see any logs from my console app. This is how I start the application:

    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();
            });

And this is my applicationsettings.json

{
  "Logging": {
    "IncludeScopes": true,
    "LogLevel": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ApplicationInsights": {
    "InstrumentationKey": ".....",
    "LogLevel": {
      "Default": "Information"
    }
  },
  "ServiceBus": {
    "ConnectionString": "..."
  },
  "ConnectionStrings": {
    "DatabaseContext": "...",
    
  }

What is the right way of adding monitoring to these type of applications?

[EDIT]

This is my deployment yaml file. I am running it from an Azure DevOps pipeline

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}

This is my deployment task. I am doing -f and passing the previous file

- 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'

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To see Information level message, you should change settings in your applicationsettings.json:

put the ApplicationInsights section into Logging section. Like below:

 {
     "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Information",
          "Microsoft.Hosting.Lifetime": "Information"
        },
        "ApplicationInsights": {
          "LogLevel": {
            "Default": "Information",
            "System": "Information",
            "Microsoft": "Information"
          }
        }
      },

    //other settings.
  }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...