-2

I am writing error to event log but when i checked for leakage i got event log leakage in .net profiler, Do I need to dispose this object? Is it will create any issue in multi threading?

public override void ProcessWarning(string title, string message)
{
    if (title == null)
        eventLog.WriteEntry(message, EventLogEntryType.Warning);
    else
        eventLog.WriteEntry(title + '\n' + message, EventLogEntryType.Warning);
    }
}
mnwsmit
  • 1,198
  • 2
  • 15
  • 31
Sreetha K
  • 21
  • 1
  • 7
  • Post the *relevant* code. Where do you define `eventLog`, where do you initialize it and why don't you dispose it in the parent class's Dispose method? – Panagiotis Kanavos Jun 21 '16 at 12:57

1 Answers1

0

The EventLog class extends Component, which shows that it implements IDisposable. So yes, you will need to (eventually) Dispose() of it.

Apparently your eventLog is a field in your class. This (an IDisposable field) means that your class needs to implement IDisposable itself. In your own Dispose method you will then need to dispose of that eventLog.

And of course this means that anything using this class must treat it as the IDisposable that it now is.

Hans Kesting
  • 38,117
  • 9
  • 79
  • 111