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

Added Serilog logging support to the project #22

Closed yogendrasgautam closed 1 month ago

yogendrasgautam commented 1 month ago

Implemented the logging for API and considered below points

The changes can be deployed to staging and tested. Sanitization part is pending.

Points to discuss/consider

Please let me know your preference ?

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.
  3. Testing:

    • [ ] Conduct tests to verify that all relevant information is being logged correctly.
    • [ ] Test the performance impact of logging to ensure it remains minimal.
    • [ ] Validate that sensitive information is properly masked or omitted from the logs.
    • [ ] Ensure that logs are stored securely and are accessible only to authorized personnel.
    • [ ] Test log retrieval and analysis to ensure logs are useful for monitoring and debugging.
  4. Deployment and Monitoring:

    • [ ] Deploy the logging solution in a staging environment and monitor its performance and accuracy.
    • [ ] Make any necessary adjustments based on initial deployment feedback.
    • [ ] Deploy the logging solution to the production environment.
    • [ ] Set up alerts and monitoring based on log data to proactively identify and address issues.
yogendrasgautam commented 1 month ago

@NicolasBuscarini Do you have staging environment, where we can test logging solution? Docker service should be running in server.

yogendrasgautam commented 1 month ago

To prevent logging the sensitive response body used traceResponseBody boolean header with request.

By Default if header is not provided, we will trcae the request and response body.

NicolasBuscarini commented 1 month ago

@NicolasBuscarini Do you have staging environment, where we can test logging solution? Docker service should be running in server.

At the moment, no. I had issues with billing on Azure. I was supposed to try creating the services for free, but I haven't managed to do it yet.

Regarding the Deployment and Monitoring tasks and some of the Testing tasks, you might not be able to complete all of them. However, it's not a problem as we can handle them once I resolve the Azure issue.