Skip to content

hasanuxaman/RequestLoggingMiddlewareApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Request Logging Middleware App

A minimal ASP.NET Core Web API project demonstrating how to implement custom middleware for logging HTTP requests and handling runtime exceptions.


πŸ“Œ Features

  • βœ… Custom middleware for request logging
  • βœ… Global exception handling in middleware
  • βœ… Logs saved to file using Serilog (optional)
  • βœ… Clean and modular codebase
  • βœ… Supports Swagger UI for testing

🧱 Tech Stack

  • Backend: ASP.NET Core Web API
  • Language: C#
  • Middleware: Custom-built
  • Logging: Console and File (via Serilog)
  • Docs: Swagger (OpenAPI)

πŸ“ Project Structure

RequestLoggingMiddlewareApp/ β”œβ”€β”€ Controllers/ β”‚ └── WeatherController.cs β”œβ”€β”€ Middlewares/ β”‚ └── RequestLoggingMiddleware.cs β”‚ └── RequestLoggingMiddlewareExtensions.cs β”œβ”€β”€ Logs/ β”‚ └── requests.txt β”œβ”€β”€ Program.cs β”œβ”€β”€ appsettings.json └── README.md


πŸš€ Getting Started

1. Clone the repo

git clone https://github.com/yourusername/RequestLoggingMiddlewareApp.git
cd RequestLoggingMiddlewareApp
2. Restore packages
bash
dotnet restore
3. Run the app
bash
Copy
Edit
dotnet run
4. Open Swagger
Go to https://localhost:5001/swagger in your browser.

πŸ§ͺ Sample Endpoint
http
GET /weather/today
πŸ” Sample Output:
json
Copy
Edit
{
  "error": "An error occurred: Cannot divide by zero.",
  "details": "Attempted to divide by zero."
}
πŸ“„ Logs Preview
txt
[2025-07-29T10:00:01Z] Request: GET /weather/today
[2025-07-29T10:00:01Z] Error: System.DivideByZeroException: Attempted to divide by zero.
πŸ›  Customize
You can extend the middleware to:

Log response status codes

Write to database or cloud

Enforce API keys or rate limiting

πŸ“ƒ License
This project is licensed under the MIT License.

✍️ Author
Md Hasanuzzaman Rony
LinkedIn β€’ GitHub

⭐ Star this repo
If you found this useful, give it a ⭐ on GitHub β€” it helps others find it too!

---

πŸ”§ **Next Step for You:**
- Replace all `yourusername` or profile links with your actual GitHub username.
- Add a `LICENSE` file (MIT or others) if publishing publicly.
- If you want, I can help create this as a `.zip` or upload-ready GitHub repo for you.

Let me know if you want a version tailored for .NET 6 or 7, or with NLog instead of Serilog.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages