EventLog.Source & Service Programs

M

MAL

Hello,

I am writing a service program that writes to a custom EventLog. I
would like the two classes used in the service to write messages to
the same log ideally using a different Source name for filtering etc.

So far I am having little luck. I feel that I have been through the
documentation extensively but am chasing my tail. It seems like it
should be as simple as .CreateEventSource in each class I want to
write to the custom log, but to no avail.

When I tried to just add one class to the service program, the service
program wrote to the Application Log and the class wrote to the custom
one, even though the service seemed to have created the log. (Based on
a 5 minute timer before "Newing" my class) (.AutoLog = False) The code
is straight from the service program and EventLog walkthroughs (which
I end up using to clean things up (RemoveSource(s), DeleteLog) before
my next service removal and reboot.

The last thing I tried was creating a seperate EventLog in each class
and trying to associate the source with the log the service created. I
have attemted to pass a reference to the EventLog to the classes and
then change the source like in the multithreaded examples. I have
tried to bring the service pgms EventLog into scope in the classes.
AHHHHHHH!!!

I am obviously making this harder that it needs to be.

Thanks for reading this rant. Please advise.
 
D

David Williams , VB.NET MVP

In your OnStart function:

Dim log As EventLog

If Not EventLog.SourceExists("ServiceSourceNameOfYourChoice") Then
EventLog.CreateSource("ServiceSourceNameOfYourChoice")
End If
log = New EventLog("Application", "ServiceSourceNameOfYourChoice")

HTH

David Williams [VB.NET MVP]
 

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