Purging a Windows EvengLog using .NET based on number of days?

28 views Asked by At

Looking for some insight on managing my event log with code.

I've successfully created an event log and can write to it with no concerns.

I can see how this log will fill quickly and I want to limit the log to a certain number of days.

Anyone have any code to share or point me in the right direction? My preference is VB.NET but I can translate C#.

1

There are 1 answers

0
George Vaisey On

After some additional research, I found a method within the event log itself.

Once the variable for the event log is created you can use .ModifyOverflowPolicy(,) to have it auto trim the log when it gets too big.

allows for DoNotOverwrite, OverWriteAsneeded or OverwriteOlder

must be an integer greater than 0 and less then 365 - the number being in reference to a number of days.