Compress old log files (e.g., ZIP after 7 days)?
Ask by ICSM Computer
Updated 29 May 2025
Great idea. Compressing old logs after 7 days reduces disk usage and keeps your app clean.
Here’s a step-by-step plan to automatically compress log files older than 7 days into
.zipfiles and optionally delete the originals.Step 1: Add NuGet Reference (if needed)
If you're not already referencing
System.IO.Compression.FileSystem, install it via NuGet:Step 2: Compression Helper (ZIP Old Logs)
Step 3: Call It Periodically (e.g., Global.asax or Scheduler)
In
Global.asax.cs:Or schedule it using a background task or external job if your app runs long-term.
Result
UserActivityLog_2025-05-20.txt→UserActivityLog_2025-05-20.zip.txtis deleted (can be optional)Optional Enhancements:
~/App_Data/LogArchive?