This is a demo project that shows how to send logs from a custom .NET Core application to Grafana using Promtail and Loki. All components are containerized using Docker Compose.
grafana-dotnet-logging/
βββ dotnet-app/
β βββ Program.cs # Writes logs to app.log
β βββ LoggingDemo.csproj # .NET 8 project
β βββ Dockerfile # Containerizes the app
β βββ logs/ # Output log file directory (bind-mounted)
βββ promtail-config.yaml # Promtail config for scraping app.log
βββ docker-compose.yml # Defines Loki, Grafana, Promtail services
βββ README.md
# Build the .NET logging app
cd dotnet-app
docker build -t dotnet-log .
# Run the logging app (this writes logs into logs/app.log)
docker run --rm -v $(pwd)/logs:/app/logs dotnet-log
# Start Grafana, Loki and Promtail
cd ..
docker-compose up --build- Access Grafana: http://localhost:3000
- Username:
admin, Password:admin
- Username:
- Add Loki as a data source if not added automatically:
- Data Sources β Add β Loki β URL:
http://loki:3100
- Data Sources β Add β Loki β URL:
- Go to Explore
- Use query:
{job="dotnet-app"}
You should see the logs generated by the .NET app.
| Tool | Purpose |
|---|---|
| Grafana | Visualization dashboards |
| Loki | Log storage (time-series) |
| Promtail | Log shipper to Loki |
| .NET | Custom log-producing app |