How to set the retention period of event log in the event viewer in days.

PRAKASH Ayush 0 Reputation points
2025-03-18T14:16:44.1833333+00:00

I am currently working with Windows Server 2022 and I need assistance in adjusting the event log settings. Specifically, I would like to set a retention policy for event logs with a particular log name to be based on a specified number of days, rather than by size. I want the event logs that are older than this defined period to be cleared automatically by Event Viewer.

Is there a way to achieve this within Event Viewer? If there are any alternative methods or approaches to implement a days-based retention policy for event logs, I would greatly appreciate your guidance.

Also, I found the below reference which might be of use regarding this query, so kindly explain how use the method given in the reference if it is related to my query.

https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-gpsb/0b9673a7-ce0a-49b4-912b-591efdb37cdf

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
11,442 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Ian Xue-MSFT 41,716 Reputation points Microsoft External Staff
    2025-03-19T07:18:08.41+00:00

    Hi,

    You can open Task Scheduler and create a scheduled task that runs periodically. Add a new trigger and configure the "Repeat task every" setting under advanced settings. In the Actions tab, run the command wevtutil cl <Logname> to clear the specified log.

    Best Regards,

    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.