Welcome to the .NET API with Elasticsearch, Kibana, and Serilog Integration project! This repository demonstrates how to build a .NET API that integrates with Elasticsearch for logging, visualizes logs in Kibana, and uses Serilog for structured logging. The project follows best practices and is built with .NET 8.
-
API Endpoints:
- Provides a sample Product API with endpoints to retrieve product details.
- Implements structured logging using Serilog.
-
Elasticsearch Integration:
- Logs API activity to Elasticsearch for efficient search and analysis.
- Configurable Elasticsearch sink for Serilog.
-
Kibana Dashboard:
- Visualizes logs in Kibana.
- Helps in monitoring and troubleshooting with rich data insights.
-
Global Error Handling:
- Implements global error handling middleware.
- Logs detailed error information including request and response context.
To install and run the application, follow these steps:
- Clone the repository from GitHub:
git clone https://github.com/Hemmatiali/dotnet-api-elasticsearch-kibana-serilog.git
cd dotnet-api-elasticsearch-kibana-serilog
-
Ensure Docker is installed and running on your machine.
-
Build and start the Docker containers:
docker-compose up --build
- Stopping Docker Containers:
docker-compose down
- Debugging with Visual Studio:
- Open the solution in Visual Studio.
- Ensure Docker support is enabled.
- Set the project as the startup project.
- Press F5 to start debugging.
API Endpoint Retrieve a product by ID:
Swagger http://localhost:5297/swagger
GET http://localhost:5297/api/product/-1
Log Visualization in Kibana
- Open Kibana at:
http://localhost:5601
- Navigate to the "Discover" tab.
- Select the index pattern corresponding to your logs (e.g., logstash-*).
- Use the following search query to filter error logs:
level: "Error"
ElasticSearch Open Elasticsearch at:
http://localhost:9200
The code is thoroughly documented with XML comments explaining the functionality of each component and method. Clear instructions are provided on how to build, run, and use the application.
This project is licensed under the MIT License - see the LICENSE file for details.