This project demonstrates how to implement a .NET Minimal API with ELK (Elasticsearch, Logstash, Kibana) Stack integration for logging and monitoring. The application provides a simple endpoint to receive log data and store it in Elasticsearch, which can then be visualized using Kibana.
- .NET 9.0
- NEST (Elasticsearch .NET Client)
- Serilog
- Docker
- ELK Stack
- Elasticsearch 7.17.9
- Kibana 7.17.9
MinimalApiElk/: Main API projectModels/: Contains data modelsProgram.cs: Application entry point and API configurationDockerfile: Container configuration for the API
docker-compose.yml: Docker compose configuration for all services
- Clone the repository:
git clone <repository-url>
cd dotnet-minimalapi-elk-stack- Start the services using Docker Compose:
docker compose up -d-
Wait for all services to start (this might take a few minutes for Elasticsearch and Kibana)
-
The following services will be available:
- API: http://localhost:5001
- Elasticsearch: http://localhost:9200
- Kibana: http://localhost:5601
Accepts log data and stores it in Elasticsearch.
Example request:
curl -X POST http://localhost:5001/api/logs \
-H "Content-Type: application/json" \
-d '{
"message": "Test log message",
"level": "Information",
"additionalData": {
"category": "test",
"userId": "123"
}
}'-
Open Kibana at http://localhost:5601
-
Navigate to Stack Management > Index Patterns
-
Create new index patterns:
For api logs:- Pattern:
api-logs-* - Timestamp field:
@timestamp
For app logs: - Pattern:
app-logs-* - Timestamp field:
@timestamp
-
Go to Discover to view your logs
The following environment variables can be configured in docker-compose.yml:
ASPNETCORE_ENVIRONMENT: Application environment (Development, Production)ElasticConfiguration__Uri: Elasticsearch connection URLElasticConfiguration__DefaultIndex: Default index name for logs
To run the project locally without Docker:
- Start Elasticsearch and Kibana using Docker:
docker compose up elasticsearch kibana -d- Run the API project:
cd MinimalApiElk
dotnet run