Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3499422
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:36:35+00:00 2026-05-18T12:36:35+00:00

Hey Folks. I have an app that writes to the windows event log. Now

  • 0

Hey Folks.
I have an app that writes to the windows event log.
Now i want the same app to be able to read the event log an process the info that is in there.

I use my own dll to do my reading and writing. The Code for the Reading:

    public static EventLog getEventLog(string Source, string Log)
    {
        using(EventLog ev = new EventLog(Log, System.Environment.MachineName, Source))
        {
            if (ev.Entries.Count <= 0)
            {
                return null;
            }
            else 
            { 
                return ev; 

            }            
        }
    }

Here is the code i use to handle the eventlog

private void ProcessEvents()
    {
        using (EventLog ev = EventComms.EventComms.getEventLog("Application", "Application"))
        {
            for (int i = ev.Entries.Count - 1; i >= ev.Entries.Count; i--)
            {
                EventLogEntry CurrentEntry = ev.Entries[i];
                Console.WriteLine("Event ID : " + CurrentEntry.InstanceId);
                Console.WriteLine("Entry Type : " + CurrentEntry.EntryType.ToString());
                Console.WriteLine("Message :  " + CurrentEntry.Message + "\n");
            }   
        }                
    }

Now when i try and do something with the returned Log i get an (ObjectDisposedException was unhandled Message=Cannot access a disposed object.) exception.
I get the exception when i use ev.Entries.Count

Why do i get the error, and what is the best way to deal with it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T12:36:35+00:00Added an answer on May 18, 2026 at 12:36 pm

    You are disposing the returned EventLog object in the getEventLog method. Remove the using statement. Actually, the getEventLog method can return null which you don’t check for later. I suggest dropping the method all together and using this code instead (where I also changed how you loop):

    private void ProcessEvents()
    {
      using (EventLog ev = new EventLog("Application", System.Environment.MachineName, "Application"))
      {
        for (int i = ev.Entries.Count - 1; i >= 0; i--)
        {
          EventLogEntry CurrentEntry = ev.Entries[i];
          Console.WriteLine("Event ID : " + CurrentEntry.InstanceId);
          Console.WriteLine("Entry Type : " + CurrentEntry.EntryType.ToString());
          Console.WriteLine("Message :  " + CurrentEntry.Message + "\n");
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey Folks, I have a tree and using proper fields and variables, I want
Hey folks, I have a field within a table that I need to do
*Hey , I have finished developing my app In my iphone apps I have
Hey folks, every once in a while I have the need to automate data
Hey folks, hoping you can help me get started with IronRuby. I have several
Hey folks, I have a question which feels stupid but I can't quite say
Hey folks, diving into jQuery and loving it. I have a set of links
Hey Folks. I have a reasonably large commercial project (so for-pay licensing is always
Hey Folks,I have pasted my code here. Dialog.inform contains a 'long' value which is
Hey folks, sorry this is a bit of a longer question... I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.