frusDev
frusDev

Reputation: 1978

IOException writing to event log

We came across this exception today that kept repeating any time we retried the action causing it

System.IO.IOException: Insufficient system resources exist to complete the requested service.

   at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
   at Microsoft.Win32.RegistryKey.SetValue(String name, Object value, RegistryValueKind valueKind)
   at System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
   at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message)
   at DoWork()

A reboot fixed this issue for us but doesn't explain the root cause. We typically write a source less than 20 characters and a message less than 100. Resource usage appeared fine on the machine running the code.

Upvotes: 1

Views: 376

Answers (1)

frusDev
frusDev

Reputation: 1978

I dug in a little deeper after the reboot was done and got a copy of the application log from the event viewer. There were ~66,000 events for that day only. I wrote a test app to write 66,000 unique messages to the log and it completed pretty quickly.

Then I noticed we had a different source for every 10 or so messages so I changed my test app to write a unique source and message every time. After about 15 minutes it only wrote 6000.

Though I wasn't able to reproduce the exception in the question I believe our problem was that we were creating new EventSources needlessly and often which goes against the recommended way of writing to the event log.

As an addendum, if the sources already existed, it wouldn't be nearly as big an issue

Upvotes: 1

Related Questions