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!
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