Org-FoodService / FoodServiceAPI

FoodService is a .NET 8.0-based service, optimizing snack bar operations through menu management, inventory tracking, and potential delivery integration. With Docker and SQLServer dependencies, it streamlines processes for snack bar owners, enhancing efficiency and customer experience.
https://foodservice-api.azurewebsites.net/swagger
2 stars 1 forks source link

Implement Logging for API #18

Closed NicolasBuscarini closed 1 month ago

NicolasBuscarini commented 1 month ago

Technical Story

Title: Implement Logging for API

Description: To improve monitoring, debugging, and maintenance of the FoodService API, we need to implement comprehensive logging using the Microsoft.Extensions.Logging package. This will capture detailed information about API requests and responses, errors, and other significant events, enabling better traceability and issue resolution.

Acceptance Criteria:

  1. Logging should capture:
    • Timestamps for each log entry.
    • Details of incoming API requests (HTTP method, endpoint, headers, parameters, request body).
    • Details of API responses (status code, response body).
    • Error messages and stack traces for any exceptions or failures.
    • Performance metrics, such as request processing time.
  2. Logs should be stored in a centralized and easily accessible location.
  3. The logging solution should support different log levels (e.g., DEBUG, INFO, WARN, ERROR).
  4. Sensitive information (e.g., passwords, credit card numbers) should be masked or omitted from the logs.
  5. The implementation should have minimal impact on API performance.
  6. Ensure compliance with data protection regulations (e.g., GDPR, CCPA) regarding log data retention and security.

Tasks:

  1. Design:

    • [x] Define log formats and structures to ensure consistency and readability.
    • [x] Plan for log storage, retention, and access, considering scalability and security.
  2. Backend Development:

    • [x] Integrate Microsoft.Extensions.Logging into the API codebase.
    • [x] Configure logging providers (e.g., console, file, Azure Application Insights) as needed.
    • [x] Implement logging for incoming API requests, capturing HTTP method, endpoint, headers, parameters, and request body.
    • [x] Implement logging for API responses, capturing status code and response body.
    • [x] Implement error logging to capture and log exceptions and stack traces.
    • [x] Add performance logging to measure and record request processing times.
    • [x] Ensure sensitive information is masked or omitted in the logs.
    • [x] Configure log levels and ensure the ability to adjust them as needed.

Business Value:

Implementing comprehensive logging for the FoodService API using Microsoft.Extensions.Logging will significantly enhance our ability to monitor and maintain the system. Detailed logs will provide invaluable insights during debugging and troubleshooting, enabling faster resolution of issues. By capturing performance metrics, we can identify and address bottlenecks, improving the overall efficiency of the API. Additionally, proper logging ensures traceability and accountability, which are crucial for maintaining a reliable and secure system. Ultimately, this will lead to higher system stability and better service quality for our customers.

yogendrasgautam commented 1 month ago

Hey @NicolasBuscarini , Let me know if I can take this feature? Also would like to know if you want logs in log file or console?

NicolasBuscarini commented 1 month ago

Yes, you can take this feature. I prefer the logs to be stored in a log file, but if you prefer, they can be in the console as well.

Thanks @yogendrasgautam !