473,554 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading the Windows Event Log

Hey

I am trying to read the Windows Event Logc. In fact, I am able to read the
Event Log. My problem is that I am reading and filtering a large log and it
takes a very very very very long time to complete. I am using the ordinary
technique for reading/writing from and to the Event Log. I am wondering if
there is a better way to speed things up. Below is an excerpt of the code I
am using (notice that I am filtering by Category and TimeGenerated; again
this works fine on small logs but is painfully sloooooooowwwww on large ones):

DateTime eventDate = DateTime.MinVal ue;
EventLog eventLog = new EventLog(logNam e, machine);

foreach(EventLo gEntry logEntry in eventLog.Entrie s)
{
if(logEntry.Cat egory == "Logon/Logoff" && logEntry.TimeGe nerated > eventDate)
{
//print the values
Console.Write(C onvert.ToString (logEntry.Entry Type) + "\t" +
logEntry.TimeGe nerated.ToStrin g() + "\t" + logEntry.Catego ry + "\t" +
logEntry.UserNa me + "\n");
}
}

Please help.

Thanks
KK

Apr 8 '06 #1
1 16732
I suppose you are connecting to a remote system, in this case you might
speed up the process considerably by using System.Manageme nt and WMI.
Here is a complete sample, but I suggest you consult MSDN and the platform
sdk docs to get an idea what is done at the WMI level.
using System;
using System.Manageme nt;
using System.IO;
class App {
[MTAThread]
private static void Main(string[] args)
{
// Beware! the account used to connect must have remote WMI privileges on
the remote server.

RunProcess M = new RunProcess("adm inuser", "adminpwd", "remservername" );
M.Run();
}
}
sealed class RunProcess
{
private ConnectionOptio ns co;
private ManagementScope scope;

public RunProcess(stri ng ConnectionUser, string ConnectionPassw ord, string
Machine )
{
co = new ConnectionOptio ns();
co.Username = ConnectionUser;
co.Password = ConnectionPassw ord;
co.Impersonatio n = ImpersonationLe vel.Impersonate ;
scope = new ManagementScope (@"\\" + Machine + @"\root\cimv 2", co);
scope.Connect() ;
}
public void Run()
{
string logFileName = "security";
// default blocksize = 1, larger value may increase network throughput
EnumerationOpti ons opt = new EnumerationOpti ons();
opt.BlockSize = 1000;
// Get only Logon/LogOff category from security log
SelectQuery query = new SelectQuery("se lect CategoryString,
TimeGenerated, User, Type from Win32_NtLogEven t where Logfile ='" +
logFileName + "' " + "and category = 2");
using(Managemen tObjectSearcher searcher = new
ManagementObjec tSearcher(scope , query, opt))
{
foreach (ManagementObje ct mo in searcher.Get()) {
string logInfo = String.Format(" {0} - {1} - {2}", mo["Type"],
mo["CategoryString "], mo["User"]);
Console.WriteLi ne(logInfo);
}
}
}
}

Willy.

"hecsan07" <he******@hotma il.com> wrote in message
news:4B******** *************** ***********@mic rosoft.com...
| Hey
|
| I am trying to read the Windows Event Logc. In fact, I am able to read the
| Event Log. My problem is that I am reading and filtering a large log and
it
| takes a very very very very long time to complete. I am using the ordinary
| technique for reading/writing from and to the Event Log. I am wondering if
| there is a better way to speed things up. Below is an excerpt of the code
I
| am using (notice that I am filtering by Category and TimeGenerated; again
| this works fine on small logs but is painfully sloooooooowwwww on large
ones):
|
| DateTime eventDate = DateTime.MinVal ue;
| EventLog eventLog = new EventLog(logNam e, machine);
|
| foreach(EventLo gEntry logEntry in eventLog.Entrie s)
| {
| if(logEntry.Cat egory == "Logon/Logoff" && logEntry.TimeGe nerated >
eventDate)
| {
| //print the values
| Console.Write(C onvert.ToString (logEntry.Entry Type) + "\t" +
| logEntry.TimeGe nerated.ToStrin g() + "\t" + logEntry.Catego ry + "\t" +
| logEntry.UserNa me + "\n");
| }
| }
|
| Please help.
|
| Thanks
| KK
|
Apr 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3728
by: David Bear | last post by:
I would like to develop some tools to better understand/analyze windows event logs. What I've done is export the event log as a delimited file, then try to use awk or python to parse the info. There must be an easier way... The format of the event changes with the event, so it seems impossible to write a generalized parser. I guess i'm...
0
504
by: Simon Wallis | last post by:
Can someone explain what Windows Event Trace is? I'm investigating EIF and Logging Application Block. Both refer to WET but I don't know what it is and can't find detailed information on it. What does it allow me to do? Is it customizable? Extensible? How do I interface with it programattically?
4
14678
by: Greg Smith | last post by:
I have an old application that analyzes the data in the event log on one of our servers. I would like to convert it to C#. Does anybody know of any examples of reading the event log on a remote system in C#. Any help is greatly appreciated.
2
1407
by: Gas | last post by:
Hi, Can anyone tell me how can I log an Windows Event Log using C#? Gas
1
2320
by: Charlie | last post by:
Hi: I would like to query the Windows Event log and display items in a DataGrid on a WinForm. Is there a class in the framework to retieve data from the Event log? Thanks, Charlie
2
3503
by: Abra | last post by:
Hi, I would like to be able from my C# .NET application to send (programatically) different debug messages to an own directory in the standard Windows Event Viewer. Which .NET classes provide access to the Windows Event Viewer ? Is it possible to configure it to automatically log the messages into files after a given amount of records ? Is it...
1
5783
by: Sean | last post by:
Here is a code I found that notifies if an event has been generated. I still can't find anything that would actually grab the event and export it a file which is what I am trying to do #include <windows.h> #include <stdio.h> BOOL notifyChange(LPCTSTR logSource) {
9
1885
by: Jack | last post by:
Here is a code I found that notifies if an event has been generated. I still can't find anything that would actually grab the event and export it a file which is what I am trying to do #include <windows.h> #include <stdio.h> BOOL notifyChange(LPCTSTR logSource) { BOOL bSuccess;
2
2827
by: Zytan | last post by:
What's a Window event log? EventLog documentation basically assumes the reader knows what it is. It says the following: http://msdn2.microsoft.com/en-us/library/system.diagnostics.eventlog.aspx "EventLog lets you access or customize Windows event logs, which record information about important software or hardware events." ...
0
7578
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7497
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7780
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7530
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5414
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5136
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3539
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1994
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.