Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
ICSM Computer
29-May-2025Great 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?