henryvuong
Member
- Joined
- Sep 8, 2023
- Messages
- 15
- Programming Experience
- 3-5
I have written a Windows Service program with C# .NET. For every task this program executes, it will write an entry into a log file (.txt format) with a datetime stamp. Everything works fine, but my concern is that the log file can eventually grow too big without my attention. I need to find a way to keep this log file at certain size. Some of the methods I am thinking are:
- Every time the program writes a new entry, it will check and delete entries that are older than a certain number of days (say 90 days). This is my prefer method.
- OR: When the log file grows to a certain size (say 100 MB), chop off half of the entries from the oldest first.
- OR: When the log file grows to a certain size, erase all entries and start fresh. This is not my prefer method, but if nothing else works, it can be a solution.
Last edited: