Setting maximum event log size

2.3k views Asked by At

Why is the following code not working?

if(EventLog.Exists("Foo"))
{
     EventLog.Delete("Foo");
}

if(EventLog.Exists("Foo") == false)
{
     EventLog.CreateEventSource("Foo", "Foo");

     EventLog.GetEventLogs().First(x => x.Log == "Foo").ModifyOverflowPolicy(OverflowAction.OverwriteAsNeeded, 0);
     EventLog.GetEventLogs().First(x => x.Log == "Foo").MaximumKilobytes = 100000;
}

The overflow policy is correctly being changed, but the maximum size stays at the default 512KB. What am I doing wrong?

Thanks!

1

There are 1 answers

0
TinaMarie On BEST ANSWER

Are you sure it's not throwing an exception? The MaximumKilobytes value must be divisible by 64.

See:

http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.maximumkilobytes.aspx