473,699 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

slow reading of eventlog

I need to read the entire eventlog and parse it. The application uses vb.net and the EventLog object. The problem i'm having is that it can take less then a second up to 15 seconds to read all entries in the eventlog. I used Perfmon and found the following two counters that were used heavily

..NET CLR Security Total Runtime Check

..NET CLR Interop # of marshallin

I have written some sample code that shows my problem

Module Module
'<System.Securi ty.SuppressUnma nagedCodeSecuri ty()>
Sub Main(
'Dim evl As New EventLog("Syste m"
Dim evl As New EventLog("Appli cation"

Dim str As Strin
Dim startTime, endTime As Dat

str = "No entries: " & evl.Entries.Cou n
Debug.WriteLine (str
Console.WriteLi ne(str

For x As Integer = 0 To
startTime = No

For Each entry As EventLogEntry In evl.Entrie
str = entry.UserName & entry.Source & entry.MachineNa me &
entry.Category & entry.CategoryN umber & entry.EntryType &
entry.EventID & entry.Index & entry.TimeGener ated & entry.Messag
Nex

endTime = No

str = "Started: " & startTime.ToStr ing("HH:mm:ss.f fff") & vbCrLf &
"Ended: " & endTime.ToStrin g("HH:mm:ss.fff f"

Debug.WriteLine (str
Console.WriteLi ne(str
Nex
End Su
End Modul

When i run it on a P4 machine (3GHz and 2G ram) i get the following results
No entries: 170
Started: 12:04:34.875
Ended: 12:04:38.890

No entries: 193
Started: 12:05:37.937
Ended: 12:05:39.859

Since the application i'm writing is a graphical one i don't want any hangings

Any ideas how i can trim the system or change the code to make it run faster
Nov 22 '05
12 2369
Hi Dominique,

I tested it and the test is bellow.

With short strings I had almost the same results as you.
Although using the SB was the fastest while the concatanation of short
strings in line was almost the same.

What was also slightly different with me was that the creation of the SB
inside the loop the time was twice as much as with setting the length to 0,
(that test with new SB is not included).

However when the strings become longer, what is in the end of the test, I
had to bring the test down to 1000 loops when I did not wanted to wait to
long using something other than the stringbuilder.

Maybe you can have a look at it and when I did test something wrong tell me?

Cor

Module Teststrings
Public Sub main()
Dim arl As New ArrayList
arl.Add("This is string one")
arl.Add("This is string two")
arl.Add("This is string three")
arl.Add("This is string four")
arl.Add("This is string five")
arl.Add("This is string six")
arl.Add("This is string seven")
arl.Add("This is string eight")
arl.Add("This is string nine")
arl.Add("This is string ten")
Dim str As String
Dim start As Integer = Environment.Tic kCount
Dim sb As New System.Text.Str ingBuilder("")
For i As Integer = 0 To 100000
sb.Length = 0
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Short strings with stringbuilder: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString & arl(1).ToString & arl(3).ToString _
& arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Short strings with concat in row: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Short strings with concat row by row: " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}",
arl(0).ToString , _
arl(1).ToString , arl(2).ToString , arl(3).ToString ,
arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Short strings with format :" & _
(Environment.Ti ckCount - start).ToString )
'Concetanation
start = Environment.Tic kCount
sb.Length = 0
For i As Integer = 0 To 1000
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Building a long string with sb : " & _
(Environment.Ti ckCount - start).ToString )
str = ""
start = Environment.Tic kCount
For i As Integer = 0 To 1000
str &= arl(0).ToString & arl(1).ToString & _
arl(3).ToString & arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat in a row : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}", _
arl(0).ToString , arl(1).ToString , arl(2).ToString , _
arl(3).ToString , arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Building a long string with format : " _
& (Environment.Ti ckCount - start).ToString )
End Sub
End Module
Nov 22 '05 #11
Hi Dominique,

I tested it and the test is bellow.

With short strings I had almost the same results as you.
Although using the SB was the fastest while the concatanation of short
strings in line was almost the same.

What was also slightly different with me was that the creation of the SB
inside the loop the time was twice as much as with setting the length to 0,
(that test with new SB is not included).

However when the strings become longer, what is in the end of the test, I
had to bring the test down to 1000 loops when I did not wanted to wait to
long using something other than the stringbuilder.

Maybe you can have a look at it and when I did test something wrong tell me?

Cor

Module Teststrings
Public Sub main()
Dim arl As New ArrayList
arl.Add("This is string one")
arl.Add("This is string two")
arl.Add("This is string three")
arl.Add("This is string four")
arl.Add("This is string five")
arl.Add("This is string six")
arl.Add("This is string seven")
arl.Add("This is string eight")
arl.Add("This is string nine")
arl.Add("This is string ten")
Dim str As String
Dim start As Integer = Environment.Tic kCount
Dim sb As New System.Text.Str ingBuilder("")
For i As Integer = 0 To 100000
sb.Length = 0
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Short strings with stringbuilder: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString & arl(1).ToString & arl(3).ToString _
& arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Short strings with concat in row: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Short strings with concat row by row: " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}",
arl(0).ToString , _
arl(1).ToString , arl(2).ToString , arl(3).ToString ,
arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Short strings with format :" & _
(Environment.Ti ckCount - start).ToString )
'Concetanation
start = Environment.Tic kCount
sb.Length = 0
For i As Integer = 0 To 1000
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Building a long string with sb : " & _
(Environment.Ti ckCount - start).ToString )
str = ""
start = Environment.Tic kCount
For i As Integer = 0 To 1000
str &= arl(0).ToString & arl(1).ToString & _
arl(3).ToString & arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat in a row : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}", _
arl(0).ToString , arl(1).ToString , arl(2).ToString , _
arl(3).ToString , arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Building a long string with format : " _
& (Environment.Ti ckCount - start).ToString )
End Sub
End Module
Nov 22 '05 #12
Hi Dominique,

I tested it and the test is bellow.

With short strings I had almost the same results as you.
Although using the SB was the fastest while the concatanation of short
strings in line was almost the same.

What was also slightly different with me was that the creation of the SB
inside the loop the time was twice as much as with setting the length to 0,
(that test with new SB is not included).

However when the strings become longer, what is in the end of the test, I
had to bring the test down to 1000 loops when I did not wanted to wait to
long using something other than the stringbuilder.

Maybe you can have a look at it and when I did test something wrong tell me?

Cor

Module Teststrings
Public Sub main()
Dim arl As New ArrayList
arl.Add("This is string one")
arl.Add("This is string two")
arl.Add("This is string three")
arl.Add("This is string four")
arl.Add("This is string five")
arl.Add("This is string six")
arl.Add("This is string seven")
arl.Add("This is string eight")
arl.Add("This is string nine")
arl.Add("This is string ten")
Dim str As String
Dim start As Integer = Environment.Tic kCount
Dim sb As New System.Text.Str ingBuilder("")
For i As Integer = 0 To 100000
sb.Length = 0
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Short strings with stringbuilder: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString & arl(1).ToString & arl(3).ToString _
& arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Short strings with concat in row: " & _
(Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Short strings with concat row by row: " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
For i As Integer = 0 To 100000
str = str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}",
arl(0).ToString , _
arl(1).ToString , arl(2).ToString , arl(3).ToString ,
arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Short strings with format :" & _
(Environment.Ti ckCount - start).ToString )
'Concetanation
start = Environment.Tic kCount
sb.Length = 0
For i As Integer = 0 To 1000
sb.Append(arl(0 ).ToString)
sb.Append(arl(1 ).ToString)
sb.Append(arl(2 ).ToString)
sb.Append(arl(3 ).ToString)
sb.Append(arl(4 ).ToString)
sb.Append(arl(5 ).ToString)
sb.Append(arl(6 ).ToString)
sb.Append(arl(7 ).ToString)
sb.Append(arl(8 ).ToString)
sb.Append(arl(9 ).ToString)
Next
str = sb.ToString
MessageBox.Show ("Building a long string with sb : " & _
(Environment.Ti ckCount - start).ToString )
str = ""
start = Environment.Tic kCount
For i As Integer = 0 To 1000
str &= arl(0).ToString & arl(1).ToString & _
arl(3).ToString & arl(4).ToString & arl(5).ToString & _
arl(6).ToString & arl(7).ToString & arl(8).ToString &
arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat in a row : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= arl(0).ToString
str &= arl(1).ToString
str &= arl(2).ToString
str &= arl(3).ToString
str &= arl(4).ToString
str &= arl(5).ToString
str &= arl(6).ToString
str &= arl(7).ToString
str &= arl(8).ToString
str &= arl(9).ToString
Next
MessageBox.Show ("Building a long string with concat : " _
& (Environment.Ti ckCount - start).ToString )
start = Environment.Tic kCount
str = ""
For i As Integer = 0 To 1000
str &= str.Format("{0} ,{1},{2},{3},{4 },{5},{6},{7},{ 8},{9}", _
arl(0).ToString , arl(1).ToString , arl(2).ToString , _
arl(3).ToString , arl(4).ToString , arl(5).ToString , _
arl(6).ToString , arl(7).ToString , arl(8).ToString ,
arl(9).ToString )
Next
MessageBox.Show ("Building a long string with format : " _
& (Environment.Ti ckCount - start).ToString )
End Sub
End Module
Nov 22 '05 #13

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

Similar topics

1
2378
by: Sauron | last post by:
Hi all I have created a Service that will listen for incoming requests from client computers and communicate with my .NET remoting objects to send data back. My problem is when I start the Service. I call the RemotingConfiguration.Configure("appname.exe.config") method, but I get a System.IO.FileNotFoundException at that line. The file does exist in the same directory as the Service's executable.
0
381
by: zorro | last post by:
I need to read the entire eventlog and parse it. The application uses vb.net and the EventLog object. The problem i'm having is that it can take less then a second up to 15 seconds to read all entries in the eventlog. I used Perfmon and found the following two counters that were used heavily ..NET CLR Security Total Runtime Check ..NET CLR Interop # of marshallin I have written some sample code that shows my problem Module Module...
3
477
by: | last post by:
I'm changing passwords every so often with my VB.net app using the NetUserSetInfo API call. I found that it is very slow, on a 3 GHz P4 it uses 18 seconds to change 100 passwords. Anyone else have the same experience ? I know for a fact that the code works. My VB.net code is as follows: Public Sub ChangePasswords() msgbox(now) Dim i As Integer For i = 0 To 100 Try Dim retVal As Long
4
14688
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.
0
1156
by: sangui | last post by:
..Net provide the class to read eventlog (EventLog class) but I try to read the window eventlog per file. without using EventLog Class. is it possible to read the log per file? public static void Main() { EventLog remoteEventLogs;
2
3544
by: Next | last post by:
Hello all, I have a windows service that was suppose to write some events into its own EventLog. I created the EventLog using the component on VS 2003 toolbar Added an installer for it. Set all the appropriate properties to assign the new Source to a new log. For some reason installutil.exe created the source in the correct log. But
3
5075
by: Ahmad Jalil Qarshi | last post by:
Hi! I am developing an application in C# as a windows NT Service. This application needs to check for eventlog using EventLog.Exists("System") But unfortunately it generates exception "Requested registry access is not allowed."
1
16749
by: hecsan07 | last post by:
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...
1
15981
by: martin | last post by:
Hi, I'm having some problems with the System.Diagnostics.EventLog class in .NET 2.0 I need to recreate an event message source inside a new log but the messages keeps ending up in the old log?! I have simplified my code into this tiny snippet: EventLog.CreateEventSource("mySrc", "myLog1");
3
4829
by: Ben | last post by:
I am trying to write an eventlog monitor. I am using the sample code provided by VB2005 SDK as the bases for my application. I need to monitor all three logs (application, system, and security). How can I monitor all three logs at once? Thanks,
0
8613
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8908
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7745
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5869
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3054
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
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.