A production-ready ASP.NET Core minimal API showcasing automatic sensitive data obfuscation in logs with Azure Application Insights integration. Built with clean modular architecture for easy microservice extraction.
- Smart Obfuscation Middleware - Automatically redacts sensitive data (credit cards, passwords, tokens) from logs before they reach Application Insights
- Azure Application Insights Integration - Seamless telemetry with custom properties and structured logging
- Modular Architecture - Self-contained modules (Orders, Payments) ready for microservice extraction
- .NET 9 Minimal APIs - Fast, lightweight, modern ASP.NET Core
- Auto-Discovery - Modules automatically registered via reflection
- Configurable - Control obfuscation patterns via
appsettings.json - OpenAPI/Swagger - Full API documentation out of the box
- Production-Ready - Includes health checks, structured logging, and comprehensive testing
- β Terraform modules and environments
- β Azure resource provisioning
- β Infrastructure versioning and state management
- β 7-stage automated deployment pipeline
- β Blue-green deployment with dual rollback strategies
- β Automated testing (regression + smoke tests)
- β PR validation with Terraform plan preview
- β Reusable workflows for code reuse
- β Auto rollback on production failures
- β Manual rollback for on-demand recovery
- β Modular architecture (Orders, Payments modules)
- β Custom middleware (obfuscation)
- β Clean code and SOLID principles
- β Modern .NET 9.0 patterns
- β Azure App Service deployment slots
- β Application Insights integration
- β Security-first approach (data obfuscation)
- β Health checks and monitoring
- .NET 9.0 - ASP.NET Core minimal APIs
- C# 13 - Records, pattern matching, modern features
- Application Insights - Azure monitoring and telemetry
- Swagger/OpenAPI - API documentation
- Terraform - Infrastructure as Code
- Azure App Service - Linux-based hosting
- GitHub Actions - CI/CD automation
- Bash Scripts - Deployment utilities
azure-appservice-logging-middleware/
βββ .github/
β βββ workflows/
β βββ deploy-blue-green.yml # 7-stage deployment pipeline (auto rollback)
β βββ manual-rollback.yml # On-demand rollback workflow
β βββ ci-pr-validation.yml # PR validation (build + terraform)
β βββ _build-app.yml # Reusable build workflow
β
βββ app/ # .NET 9.0 Application
β βββ Infrastructure/ # Module pattern implementation
β βββ Middleware/ # Obfuscation middleware
β βββ Modules/ # Orders & Payments modules
β βββ Properties/ # launchSettings.json
β βββ Program.cs
β
βββ tests/ # Test Projects
β βββ AzureAppServiceLoggingMiddleware.UnitTests/
β β βββ Middleware/
β β βββ ObfuscationMiddlewareTests.cs
β βββ AzureAppServiceLoggingMiddleware.IntegrationTests/
β βββ ObfuscationMiddlewareIntegrationTests.cs
β
βββ infrastructure/ # Terraform IaC
β βββ terraform/
β β βββ environments/
β β β βββ dev/ # Dev environment config
β β βββ modules/
β β βββ app-service/ # App Service with slots
β βββ scripts/
β
βββ docs/ # Documentation
See Repository Structure for detailed breakdown.
Module Pattern Benefits:
Each module is self-contained and follows these principles:
- Self-contained - All domain code in one folder
- Testable - Clear boundaries and interfaces
- Discoverable - Auto-registered via reflection
- Extractable - Ready for microservice split
See Module Pattern Guide for implementation details and best practices.
Automated 7-stage blue-green deployment pipeline with comprehensive rollback strategies.
Build β Terraform β Deploy to Green β Test Green β Swap β Smoke Test β Auto Rollback (if needed)
Key Features:
- β Zero-downtime deployment with blue-green slots
- β Automated rollback if production smoke tests fail
- β Manual rollback workflow for post-deployment issues
- β PR validation with Terraform plan preview
- β Comprehensive testing before production swap
Triggers:
- Push to
mainwith changes toapp/**,infrastructure/**, or.github/workflows/** - Pull requests run CI validation only (no deployment)
See CI/CD Pipeline Documentation for complete details on deployment stages, rollback strategies, and troubleshooting.
# Clone the repository
git clone https://github.com/gilbertrios/azure-appservice-logging-middleware.git
cd azure-appservice-logging-middleware/app
# Run the application
dotnet runThe API will be available at:
- HTTPS:
https://localhost:5001 - Swagger UI:
https://localhost:5001/swagger
Optional: Customize obfuscation settings in app/appsettings.json - see Configuration Guide
# 1. Configure Azure credentials (see docs/setup-guide.md)
# 2. Push to main branch
git push origin main
# The 7-stage pipeline will:
# β
Build application
# β
Provision infrastructure (Terraform)
# β
Deploy to green slot
# β
Run regression tests on green
# β
Swap to production
# β
Run smoke tests on production
# β
Auto rollback if smoke tests failThe middleware automatically detects and obfuscates sensitive properties in request/response bodies:
curl -X POST http://localhost:5000/api/payments/process \
-H "Content-Type: application/json" \
-d '{
"orderId": 1,
"amount": 299.99,
"creditCard": "1234-5678-9012-3456",
"cvv": "123",
"token": "secret-api-key"
}'{
"orderId": 1,
"amount": 299.99,
"creditCard": "***REDACTED***",
"cvv": "***REDACTED***",
"token": "***REDACTED***"
}β Actual API response remains unchanged - only logs are obfuscated!
Explore the API using Swagger UI at /swagger when running locally, or view the full endpoint documentation in the Application README.
Modules:
- Orders - Order management and status tracking
- Payments - Payment processing and refunds
- Health Check - API health status
Customize obfuscation behavior via app/appsettings.json:
{
"ObfuscationMiddleware": {
"Enabled": true,
"ObfuscationMask": "***REDACTED***",
"SensitiveProperties": ["password", "creditCard", "cvv", "ssn", "apiKey", "token"]
}
}Key features:
- Case-insensitive property matching
- Recursive JSON traversal (nested objects/arrays)
- Configurable mask pattern and sensitive property list
See Configuration Guide for complete options, Application Insights setup, environment-specific settings, and user secrets.
Uses Terraform to provision Azure App Service with blue-green deployment slots for zero-downtime releases.
Resources provisioned:
- App Service Plan (Linux, S1) with deployment slots
- App Service (production + green slot for zero-downtime deployments)
- Application Insights for telemetry and monitoring
- Log Analytics Workspace
Deploy infrastructure:
cd infrastructure/terraform/environments/dev
terraform init
terraform applySee Infrastructure README for complete details on resources, configuration, and Terraform modules.
Run the test suite to verify functionality:
# Run all tests
dotnet test
# Run only unit tests (fast)
dotnet test --filter "Category=Unit"
# Run only integration tests
dotnet test --filter "Category=Integration"Test Coverage:
- Unit tests for ObfuscationMiddleware logic and edge cases
- Integration tests for full API and middleware pipeline
- Automated execution in CI/CD pipeline
See Testing Guide for detailed test documentation, manual testing with cURL/Swagger, and coverage reports.
- Repository Structure - Folder organization
- Module Pattern Overview - Modular architecture
- Microservice Split Criteria - When to extract
- MVC vs Minimal API Pipeline - Request pipeline internals
- Infrastructure Guide - Terraform and Azure resources
- Setup Guide - Deploy to Azure step-by-step
- CI/CD Pipeline - Deployment pipeline and rollback strategies
- App Service vs Functions - Service comparison
- Application README - Run and develop locally
- Testing Guide - Test strategy, commands, and coverage
- Configuration Guide - Application settings and options
Ready for microservice extraction. See Microservice Split Criteria for detailed guidance.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- πΌ LinkedIn: Connect with me
- π§ Email: gilbertrios@hotmail.com
- π‘ GitHub: @gilbertrios
- Setup Guide - Deploy to Azure in 10 steps
- Project Summary - Overview and key decisions
- Repository Structure - Folder organization
β Star this repo if you find it useful for learning or reference!