A .NET 9 console application that automatically monitors a local folder and uploads files to Azure Blob Storage. This background service is designed for scenarios where you need to continuously back up files from a local directory to cloud storage.
- Continuous Monitoring: Automatically scans a specified folder at configurable intervals
- Azure Blob Storage Integration: Uploads files to Azure Blob Storage containers
- Background Processing: Runs as a Windows service or console application
- Automatic Cleanup: Deletes local files after successful upload
- Comprehensive Logging: Uses Serilog for detailed logging with file and console output
- Error Handling: Robust error handling with detailed logging for troubleshooting
- Configuration-based: Easy configuration through
appsettings.json - Subdirectory Support: Recursively scans all subdirectories
The application follows a clean architecture pattern with dependency injection:
- Program.cs: Application entry point and dependency injection configuration
- AppBackgroundService: Background service that orchestrates the file scanning process
- FilesService: Core service responsible for scanning folders and coordinating uploads
- AzureStorageService: Handles all Azure Blob Storage operations
- AppSettings: Configuration model with validation attributes
- .NET 9.0 SDK
- Azure Storage Account with connection string
- Windows operating system (for service deployment)
Configure the application by editing appsettings.json:
{
"AppSettings": {
"ScanIntervalMinutes": 1,
"ScanFolder": "./Backups",
"Container": "backup",
"AzureConnectionString": "Your Azure Storage Connection String"
}
}| Parameter | Description | Required | Default |
|---|---|---|---|
ScanIntervalMinutes |
Interval between folder scans (1-60 minutes) | Yes | 1 |
ScanFolder |
Local folder path to monitor | Yes | "./Backups" |
Container |
Azure Blob Storage container name | Yes | "backup" |
AzureConnectionString |
Azure Storage connection string | Yes | - |
For quick deployment, use the pre-built Docker image:
docker run -d \
-v /path/to/your/scan/folder:/app/Backups \
-v /path/to/your/logs:/app/Logs \
-e AppSettings__AzureConnectionString="your-connection-string" \
-e AppSettings__Container="your-container-name" \
-e AppSettings__ScanIntervalMinutes=1 \
-e AppSettings__MaxFilesToStore: 30 \
--name files-uploader \
ghcr.io/xhunter74/files-uploader:latestgit clone <repository-url>
cd FilesUploader
dotnet build- Create an Azure Storage Account
- Get the connection string from Azure Portal
- Update
AzureConnectionStringinappsettings.json
The application will automatically create the scan folder if it doesn't exist. By default, it monitors the ./Backups folder.
dotnet run- Initialization: The application starts and validates configuration settings
- Folder Monitoring: Every configured interval (default: 1 minute), the service scans the specified folder
- File Discovery: All files in the folder and subdirectories are identified
- Upload Process: Each file is uploaded to the specified Azure Blob Storage container
- Cleanup: After successful upload, the local file is deleted
- Logging: All operations are logged with detailed information
Local Folder β Scan β Upload to Azure β Delete Local File β Log Results
The application uses Serilog for comprehensive logging:
- Console Output: Real-time logging with colored output
- File Logging: Daily rotating log files in
Logs/directory - Debug Output: Additional debug information during development
Log files are stored in the Logs/ directory with the naming pattern uploader-log{yyyyMMdd}.txt.
To run as a Windows service, you can use tools like NSSM (Non-Sucking Service Manager):
# Install NSSM
choco install nssm
# Create service
nssm install FilesUploader "C:\path\to\FilesUploader.exe"
nssm set FilesUploader AppDirectory "C:\path\to\FilesUploader"
nssm start FilesUploaderFilesUploader/
βββ Extensions/
β βββ LoggerConfigurationUtils.cs # Serilog configuration
βββ Services/
β βββ AppBackgroundService.cs # Main background service
β βββ AzureStorageService.cs # Azure Blob operations
β βββ BaseBackgroundService.cs # Base service class
β βββ FilesService.cs # File scanning logic
βββ Settings/
β βββ AppSettings.cs # Configuration model
βββ appsettings.json # Application configuration
βββ appsettings.Development.json # Development settings
βββ Program.cs # Application entry point
βββ FilesUploader.csproj # Project file
- Azure.Storage.Blobs (12.24.1): Azure Blob Storage client
- Serilog.AspNetCore (8.0.2): Structured logging framework
- Microsoft.Extensions.Hosting: Background service hosting
- System.ComponentModel.DataAnnotations: Configuration validation
The application implements comprehensive error handling:
- Upload Failures: Files that fail to upload are logged, but the process continues
- File Access Errors: Handles locked files and permission issues
- Network Issues: Retries and logging for Azure connectivity problems
- Configuration Errors: Validates settings on startup with clear error messages
Monitor the application through:
- Log Files: Check
Logs/uploader-log{date}.txtfor detailed operation history - Console Output: Real-time status during development
- Azure Portal: Verify file uploads in the Azure Storage container
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
- Files not uploading: Check Azure connection string and container permissions
- Permission errors: Ensure the application has read/write access to the scan folder
- Files stuck in folder: Check logs for upload errors or Azure connectivity issues
- Slow uploads for large files: Large files are streamed efficiently but may take time depending on network bandwidth
- Check application logs in the
Logs/directory - Verify Azure Storage connection and container existence
- Ensure local folder permissions are correct
- Test with small files first
For support and questions:
- Check the logs first for error details
- Review configuration settings
- Ensure Azure Storage account is accessible
- Verify folder permissions and structure