I have configured nlog with elasticsearch on my application (ASP.NET Core) with nlog.config look like:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Trace"
internalLogFile="\\{ipmachine}\c\Log\internal-nlog.txt">
<extensions>
<add assembly="NLog.Targets.ElasticSearch"/>
</extensions>
<targets>
<target name="ElasticSearch" xsi:type="BufferingWrapper" flushTimeout="5000">
<target xsi:type="ElasticSearch"/>
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="ElasticSearch" />
</rules>
</nlog>
And on appsetting is : "ElasticsearchUrl": "http://localhost:9200"
When i run application by dotnet-run and I have an elk raised on a dockers like that - https://github.com/deviantony/docker-elk
It work all logs are saved.
But when i add my application to docker image then it doesn't work.
Tried configured it on the same networks on docker-compose, I did it the same with link.
...
elasticsearch:
...
networks:
- elk
...
myapp:
networks:
- elk
depends_on:
- elasticsearch
networks:
elk:
driver: bridge
Even check the ip of elacticsearch on dockerand change appsetting to "ElasticsearchUrl": "http://172.21.0.2:9200"
Then i added FileBeat on docker-compose:
filebeat:
image: docker.elastic.co/beats/filebeat:6.3.2
#command: "filebeat -e -c /etc/filebeat/filebeat.yml"
environment:
HOSTNAME: "my-server"
LOGSTASH_HOST: "localhost"
LOGSTASH_PORT: "5044"
volumes:
- "./filebeat/config/filebeat.yml:/etc/filebeat/filebeat.yml:rw"
With filebeat.yml -
output:
logstash:
enabled: true
hosts:
- elk:5000
ssl:
certificate_authorities:
- /etc/pki/tls/certs/logstash-beats.crt
timeout: 15
filebeat:
prospectors:
-
paths:
- /var/log/syslog
- /var/log/auth.log
document_type: syslog
-
paths:
- "/var/log/nginx/*.log"
document_type: nginx-access
And the logs are still not saved in the elasticsearch. It only work when I run application not via Docker. I am asking for advice.
My ports:
- 5000 - logstash
- 5601 - kibana
- 9200 - elasticsearch
- 9300 - elasticsearch
- 5044 - filebeat