Solved

How can I iterate through a component collection and read the text of each of the compnent?

Posted on 2006-11-30
6
245 Views
Last Modified: 2010-04-16
I'm using vs2005, .net 2.0.  I tried the following code to read the system Securitylog's but am getting error.  padLogEntry is an EventyLogEntry

IEnumerator IEnum = padLogEntry.Container.Components.GetEnumerator();
Error      2      Using the generic type 'System.Collections.Generic.IEnumerator<T>' requires '1' type arguments      C:\Projects\UnityAdmin\EventReport.cs      62
0
Comment
Question by:lapucca
  • 3
  • 2
6 Comments
 
LVL 29

Expert Comment

by:anarki_jimbel
ID: 18051162
Try to change:

IEnumerator<Component> IEnum = padLogEntry.Container.Components.GetEnumerator();

0
 
LVL 5

Accepted Solution

by:
rameedev earned 500 total points
ID: 18051861
if you are interesed in reading a particular evntlog's data you can use some thing like this...

EventLog[] m_EvLogArr = EventLog.GetEventLogs();
                  foreach(EventLog mTmpLog in m_EvLogArr)
                  {
                        if(mTmpLog.LogDisplayName=="YourLogName") /// padLogEntry
                        {
                              IEnumerator IEnumLog =  mTmpLog.Entries.GetEnumerator();
                              EventLogEntry m_TmpEvLogEntry;
                              while(IEnumLog.MoveNext())
                              {
                                    m_TmpEvLogEntry = (EventLogEntry)IEnumLog.Current;      

                                    Console.WriteLine(m_TmpEvLogEntry.MachineName);
                                    Console.WriteLine(m_TmpEvLogEntry.Category);
                                    Console.WriteLine(m_TmpEvLogEntry.EntryType.ToString());
                                    Console.WriteLine(m_TmpEvLogEntry.TimeWritten.ToLongDateString());
                                    Console.WriteLine(m_TmpEvLogEntry.UserName);
                                    Console.WriteLine(m_TmpEvLogEntry.Message);
                              }
                        }
                  }

0
 

Author Comment

by:lapucca
ID: 18057477
Hi rameedev,

I need to read the property of the "Security" log's entry.  I think they're stored as components and am wondering how can I read them.  thanks.

Hi anaki, I tried it but it gives an error.


Thanks.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 5

Expert Comment

by:rameedev
ID: 18066411
You mean to say you want to read msgs in the Security EventLog...Can you clarify?
0
 

Author Comment

by:lapucca
ID: 18066533
When I double click on an entry of the "Security" log in the system's "Event Viewer", a Property window pops up.  In this window, there is a "Description" section that lists many different information like "User Name:, "Domain", "Login ID"......
How can I obtain each of this inforation in my program?  Thank you.
0
 
LVL 5

Expert Comment

by:rameedev
ID: 18066562
well the above code which i gave you...you can extract most of the information
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question