Windows Service and EventLog

M

Microsoft

I'm creating a windows service with C#, but am having a huge amount of
difficulties using the event log. In the design view of the service, I drop
an EventLog component. I name the source the same as my service app and the
log property I name with an appropriate name. However, this particular log
never gets any entries, regardless of the AutoLog property. (In fact, I
have the AUtoLog property set to false, but there are still log entries in
the System log (why there??) of the start and stop routines. Regardless,
the log entries I want to make manually (using this.SrvcLog.WriteEntry())
never make it to the log file in question.

This is really befuddling me and I sure could use some advice/suggestions...
 
S

Steve Walker

Microsoft said:
This is really befuddling me and I sure could use some advice/suggestions...

Does your event logging code work when run from a console app? Does the
event source you are trying to write to exist? Does your service create
the event source if it doesn't? Some accounts have permission to write
to the log but not to create an event source. What account is the
service running as? Try configuring it to run as Administrator.
 
M

Microsoft

The service in question runs as System, so I suppose it's a permission
problem? There's no specific code that creates the eventlog if it doesn't
exist, the documentation for C# and .NET says it gets created automatically,
which it does, just doesn't receive the log entries I wish to write...

Perhaps I shouldn't use the EventLog, just come up with my own logging
scheme...
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

First a dumb question, you are not running in win 9X/ME right?

If not, it should be piece of cake using the EventLog:
Three lines are needed:

eventLog1 = new System.Diagnostics.EventLog();
//
// eventLog1
//
eventLog1.Log = "Application";
eventLog1.Source = "Fatal Crash system";

cheers,
 
M

Microsoft

I agree with you that is "should" be a piece of cake... but I cannot get
anything to log when and where I expect it to... I am running on XP Pro...
 
S

Steve Walker

Microsoft said:
The service in question runs as System, so I suppose it's a permission
problem?

Configure it as Administrator. If that fixes it, it was probably
permissions. If it doesn't, it probably wasn't. It's an easily
eliminated possibility.
There's no specific code that creates the eventlog if it doesn't
exist, the documentation for C# and .NET says it gets created automatically,
which it does, just doesn't receive the log entries I wish to write...

So your event source is in the list of filters?
 
G

Guest

I had a problem with the source being created as using the "Application" log.
I tried to change it but, every time I tried to write to a custom event log
the messages were still being written to the "Application" event log. I
changed the source name to something different and it wrote and created the
correct event log and wrote the correct message. Not sure why, but it worked.
 

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