Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

407
Visualizações
Elasticsearch, Kibana, dotnet core and docker

I have my dotnet core application set up to use SeriLog which logs to an ElasticSearch Sink. When running my dotnet core app locally with ElasticSearch and Kibana I have two separate containers I'm able to log stuff from my application to Elastic and I'm also able to see these log messages in Kibana.

When I include my dotnet core application in the docker-compose.yml file, navigating to the endpoint where the app is located, I expect it to log several messages to Elasticsearch, but it doesn't. I suspect that my application doesn't understand how to communicate with Elasticsearch when it's being containerized. My docker-compose.yml looks like this:

version: '3.0'

services:
   db:
     image: mysql:5.7
     environment:
       MYSQL_RANDOM_ROOT_PASSWORD: 1
       MYSQL_DATABASE: chtr
       MYSQL_USER: dbuser
       MYSQL_PASSWORD: dbuserpassword
     volumes:
       - dbdata:/var/lib/mysql
       - ./_MySQL_Init_Script:/docker-entrypoint-initdb.d
     restart: always

   elasticsearch:
     image: docker.elastic.co/elasticsearch/elasticsearch:6.2.4
     container_name: elasticsearch
     ports:
       - "9200:9200"
     volumes:
       - elasticsearch-data:/usr/share/elasticsearch/data

   kibana:
     image: docker.elastic.co/kibana/kibana:6.2.4
     container_name: kibana
     ports:
       - "5601:5601"
     depends_on:
       - elasticsearch     

   chtr.server:
     depends_on:
       - db
       - kibana
     image: trebias/chtr.server
     build:
       context: .
     ports:
       - "8080:80"
       - "56:5601" 

volumes:
    dbdata:
    elasticsearch-data:

chtr.server is my image being pull from my docker hub.

Over to the appsettings.json within my dotnet core application:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ElasticConfiguration": {
    "Uri": "http://[::]:9200/"
  }
}

Where I create the Logger like this in my Startup.cs file:

  var elasticSearch = Configuration["ElasticConfiguration:Uri"];
  Log.Logger = new LoggerConfiguration().Enrich.FromLogContext().WriteTo.Elasticsearch(new ElasticsearchSinkOptions(
                   new Uri(elasticSearch)) { AutoRegisterTemplate = true }).CreateLogger();

Like I said at the beginning of this post; It works when I run Kibana and Elasticsearch in containers and my app locally, but not when all three apps are in containers.

Any suggestions?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The service is running under container that's why you should write your log using the container name like bellow:

Appsettings.Development.json:

{
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Information",
      "System": "Information",
      "Microsoft": "Information"
    }
  },
  "ElasticConfiguration": {
    "Uri": "http://elasticsearch:9200/"
  }
}

You can find here a full example showing how to setup Serilog, Seq, elasticsearch and kibana to work together under Docker containers solution.

structure logging with serilog seq and elastic search under docker

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda