I have .net core app which Serilog as log framework. Right now Serilog are logging to file. I want to expose this file outside container and have a simple access as with other files.
I tried with volume and volume-bind according to docker-compose reference: https://docs.docker.com/compose/compose-file/#volume-configuration-reference
Moreover, directory from host are shared. But log file appears in container in specific directory, but directory on host are still empty.
I can manually copy this file using DOCKER COPY command. Is there any approach to make this file synchronized in my volumed directory on host?
Or should I apply some additional approach e.g. ELK to achieve my goal?
This is my docker-compose file. Frontend part is commented now because of tests.
version: '3.7'
services:
backend:
build: './backend'
ports:
- "80:80"
networks:
- gateway
environment:
- Logger:FilePath=//logs//logs.txt
- Database:Name=Data Source = ./database.db
volumes:
- type: bind
source: /Users/grzegorz/Desktop/logs
target: /app/logs/
#frontend:
# build: './frontend'
# depends_on:
# - backend
# ports:
# - "4200:4200"
# networks:
# - gateway
networks:
gateway: {}
When I open terminal and go into app/logs directory I can see logs.txt file with current application logs.
You're mounting /app/logs but the env variable indicates that logs are written to /logs, not /app/logs.
Change one path or the other and see if the problem is still there.
In general your approach is correct. But for production usage, especially in clustered environments, it's better to use serilog, splunk, application insights or other service-based log collector, as files might be difficult to maintain when you scale up your containers.