Skip to content

Conversation

ZohaiAli
Copy link

This pull request includes several improvements to the ASPNET/Program.cs startup file for better robustness, safety, and maintainability:

  1. Safe Logs Folder Creation

    • Wrapped log folder creation in a try-catch block to prevent crashes in environments with restricted permissions.
    • Ensures the Serilog logs folder is always safely initialized.
  2. Serilog Configuration

    • Configured rolling file logging to wwwroot/app_data/logs/app.log for better log management.
    • Properly closes and flushes logs on application shutdown.
  3. CORS Policy

    • Added an explicit "AllowAll" CORS policy.
    • Prevents runtime errors due to missing default CORS policy and ensures API can be called from frontend apps.
  4. Middleware Order Adjustment

    • Moved GlobalApiExceptionHandlerMiddleware after authentication and authorization middleware.
    • Ensures that auth exceptions are properly captured and logged.
  5. Safe Application Startup

    • Wrapped app.Run() in try-catch with Serilog fatal logging.
    • Prevents unhandled exceptions from crashing the application without logging.

These changes improve application stability, provide better error tracking, and make the startup process more predictable, especially in production environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant