eventlog object must be disposed?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stexcec
    New Member
    • Nov 2009
    • 3

    eventlog object must be disposed?

    hi All, I'm writing a Windows Service with a Threading Timer.
    In my application, I use EventLog to track the steps in a custom log.

    Sometimes, the program crashes with an unhandled error after a eventlog dispose() method.

    Should the problem related to threading.timer s?

    Any help will be truly appreciated!

    stefano
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    if you are using EventLog Class to log to event logs you can call dispose method to release the managed and unmanaged resources.

    Code:
    using (System.Diagnostics.EventLog e = new System.Diagnostics.EventLog())
                {              
                    e.Source = "MySource";
    
                    // Write an informational entry to the event log.    
                    e.WriteEntry("Writing to event log.");
                    
                }

    Comment

    • PRR
      Recognized Expert Contributor
      • Dec 2007
      • 750

      #3
      Regarding the error make sure your windows service has permission to write to the windows logs and also see if you are creating the "custom" log within your service. You require admin permission to create a new "source".

      Comment

      • stexcec
        New Member
        • Nov 2009
        • 3

        #4
        Thanks to all. I've solved my problem removing the line:

        eventlog.Enable RaisingEvents = True;

        Ciao

        Comment

        Working...