trashvin
trashvin

Reputation: 595

Can Microsoft.VisualBasic.Logging.FileLogTraceListener be set to retain the 5 most recent log only

Im using Microsoft.VisualBasic.Logging.FileLogTraceListener in my C# app for logging. I have set it to roll the log files daily. See my setting below:

<add name="TextListener"
      type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
      traceOutputOptions="DateTime,ProcessId,ThreadId"
      customLocation=""
      location="ExecutableDirectory"
      logFileCreationSchedule="Daily"
      baseFileName="TestAppLog"/>

My issue is that it simply keeps the old files in the system, so even if the daily files are small eventually it will accumulate. My ideal scenario would be to keep only the log files from the last 10 days, any thing older than that it is deleted from the system.

Is there a way to do it on the Microsoft.VisualBasic.Logging.FileLogTraceListener setting? If none, whats the best approach to implement this automatic purging of old data?

Upvotes: 1

Views: 765

Answers (1)

kennyzx
kennyzx

Reputation: 12993

I can't find such setting in the documentation.

What I can think of is, setting up a scheduled task to clean up the outdated logs, daily. The scheduled task can be an exe or a batch, pretty easy to implement and deploy.

Here is an example written in PowerShell:

Delete files older than 15 days using PowerShell

and how to configure it in Task Scheduler

Use the Windows Task Scheduler to Run a Windows PowerShell Script

Upvotes: 1

Related Questions