1

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?

trashvin
  • 545
  • 1
  • 5
  • 14

1 Answers1

1

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

kennyzx
  • 12,845
  • 6
  • 39
  • 83
  • thanks! I will look into the links you provided. Ultimately, i would like a solution that is handled by my app itself, such as extending the Microsoft.VisualBasic.Logging.FileLogTraceListener class to support purging. – trashvin Jul 26 '18 at 06:03
  • Yes, I had thought of that option...a custom text listener inherits from `FileLogTraceListener` which purges the dated logs, but _where_ to put the purging code? the constructor? - not sure if a new instance of `FileLogTraceListener` is created every day or it keeps using the same instance. One of the many Write/Trace overrides? – kennyzx Jul 26 '18 at 06:10