markmcdowell / NLog.Targets.ElasticSearch

NLog target for Elasticsearch
MIT License
176 stars 89 forks source link

Dockerized project cannot connect to elastic #169

Closed bayramerenn closed 12 months ago

bayramerenn commented 1 year ago

I have a docker compose file containing elasticsearch and my project. When I tried to start the project, elasticsearch couldn't register, I didn't know where I was doing wrong, can you help?

the codes i wrote https://github.com/bayramerenn/LogingInfra

nlog.Development.config <?xml version="1.0" encoding="utf-8" ?>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true">
    <extensions>
        <add assembly="NLog.Targets.ElasticSearch"></add>
    </extensions>
    <targets>
        <target name="elastic" xsi:type="BufferingWrapper" flushTimeout="5000">
            <target xsi:type="ElasticSearch" 
                    uri="${configsetting:item=ElasticUrl}" 
                    index="Development"/>
        </target>
    </targets>
    <rules>
        <!--All logs, including from Microsoft-->
        <!--<logger name="*" minlevel="Trace" writeTo="allfile" ></logger>
    <logger name="*" minlevel="Trace" writeTo="ownFile-web" ></logger>
    <logger name="*" minlevel="Trace" writeTo="database" ></logger>-->
        <logger name="*" minlevel="Trace" writeTo="elastic" ></logger>
    </rules>
</nlog>

nlog.Production.config

<?xml version="1.0" encoding="utf-8" ?>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      autoReload="true">
    <extensions>
        <add assembly="NLog.Targets.ElasticSearch"></add>
    </extensions>
    <targets>
        <target name="elastic" xsi:type="BufferingWrapper" flushTimeout="5000">
            <target xsi:type="ElasticSearch"
                    uri="${configsetting:item=ElasticUrl}"
                    index="Production"/>
        </target>
    </targets>
    <rules>

        <logger name="*" minlevel="Trace" writeTo="elastic" ></logger>
    </rules>
</nlog>

appsettings.Development.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ElasticUrl": "http://localhost:9200/"
}

appsettings.Production.json

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ElasticUrl": "http://elasticsearch:9200/"
}

docker-compose.yml

version: "3.8"
services:
  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
    container_name: elasticsearch
    restart: always
    ports:
      - 9200:9200
    volumes:
      - elasticsearch_volume:/usr/share/elasticsearch/data
    environment:
      - xpack.monitoring.enabled=true
      - xpack.watcher.enabled=false
      - "ES_JAVA_OPTS=-Xms512m -Xmx512m"
      - discovery.type=single-node
    networks:
      - nlognet
  kibana:
    image: docker.elastic.co/kibana/kibana:7.6.2
    container_name: kibana
    restart: always
    ports:
      - 5601:5601
    depends_on:
      - elasticsearch
    environment:
      - ELASTICSEARCH_URL=http://elasticsearch:9200/
      - ELASTICSEARCH_HOSTS=http://elasticsearch:9200/
    networks:
      - nlognet
  nlog.api:
    image: nlog_api
    depends_on:
      - elasticsearch
      - kibana
    build:
      context: .
      dockerfile: NLogElastic/Dockerfile
    container_name: nlog.api
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
    ports:
      - "5005:80"
    networks:
      - nlognet

volumes:
  elasticsearch_volume:

networks:
  nlognet:
    driver: bridge
bayramerenn commented 1 year ago

the error is related to me, you can close it

snakefoot commented 1 year ago

If you can tell what was missing, then it might help others. Maybe also add answers here:

Notice you have the power to close your own issues.

bayramerenn commented 1 year ago

The error was related to me, I didn't feel the need to add it because I thought it was nothing to solve.