0

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#.

George Vaisey
  • 139
  • 1
  • 5
  • 19
  • The following may be helpful: [EventLogEntryCollection](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlogentrycollection?view=dotnet-plat-ext-6.0), [EventLogEntry](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlogentry?view=dotnet-plat-ext-6.0&viewFallbackFrom=net-6.0), and [EventLogEntryType Enum](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlogentrytype?view=dotnet-plat-ext-6.0&viewFallbackFrom=net-6.0). Also see the following registry key: `HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog`. – Tu deschizi eu inchid Nov 08 '22 at 16:26
  • I think that reading the Remarks section of the [EventLog.MinimumRetentionDays Property](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.eventlog.minimumretentiondays) documentation might help. – Andrew Morton Nov 08 '22 at 17:55

1 Answers1

0

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.

George Vaisey
  • 139
  • 1
  • 5
  • 19