writing to the event log from a service

M

Majed

hi

i'v created a service that do nothing except writing to the log event from a
timer event. but it did not
the started and stopped succesfully logs do show in the applaction log.I
created a windows form app that do the same...and it worked!?
i tried all posible account property...here is the code from my timer event

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

' Create an EventLog instance and assign its source.

Dim myLog As New EventLog

myLog.Source = "Service1"

myLog.Log = "Application"

' Write an informational entry to the event log.

myLog.WriteEntry("Writing to event log." & vbCrLf & Now.ToString)

end sub



i tried using the service eventlog like this:

Me.EventLog.WriteEntry("Service 1 stopped succesfully at:" & vbCrLf &
Now.ToString, EventLogEntryType.Warning, Now.Millisecond)

it did not work either

then i set the autolog property to false and wrot from onstart and onstop to
the log and IT WORKED!! but not from the timer event:(

is it security or WHAT?!

please help

TIA

Majed
 
G

Guest

hi

i'v created a service that do nothing except writing to the log event from a
timer event. but it did not
the started and stopped succesfully logs do show in the applaction log.I
created a windows form app that do the same...and it worked!?
i tried all posible account property...here is the code from my timer event

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Timer1.Tick

' Create an EventLog instance and assign its source.

Dim myLog As New EventLog

myLog.Source = "Service1"

myLog.Log = "Application"

' Write an informational entry to the event log.

myLog.WriteEntry("Writing to event log." & vbCrLf & Now.ToString)

end sub



i tried using the service eventlog like this:

Me.EventLog.WriteEntry("Service 1 stopped succesfully at:" & vbCrLf &
Now.ToString, EventLogEntryType.Warning, Now.Millisecond)

it did not work either

then i set the autolog property to false and wrot from onstart and onstop to
the log and IT WORKED!! but not from the timer event:(

is it security or WHAT?!

please help

TIA

Majed
 
G

Guest

This is not a security issue. It seems that you are using System.Windows.Forms.Timer which may only be used in Windows Forms. You should use System.Threading.Timer instead

Regards, Jakob.
 
M

Majed

Thanks a lot!!

Jakob Christensen said:
This is not a security issue. It seems that you are using
System.Windows.Forms.Timer which may only be used in Windows Forms. You
should use System.Threading.Timer instead.
 
J

Jay B. Harlow [MVP - Outlook]

Majed,
In addition to the others comments, the following recent articles in MSDN
Magazine explain the difference between the three timer objects in .NET &
when to use each.

http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx

http://msdn.microsoft.com/msdnmag/issues/04/03/default.aspx

The above articles also discusses if & how each timer interacts with
threading.

I'm using System.Timers.Timer (instead of System.Threading.Timer) in my
Windows Service, as I don't really need the extra features of
System.Threading.Timer. Either should work in your case.

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top