Windows Service running but event logs not working

loggingwindowswindows-services

I have a windows service listening to messages from a queue but the messages are not read from the queue.I created an event log to check for logs during service startup and shutdown but the logs are not written. I do not want to debug the service since it is a painful process.Is there a way to solve this issue.The messages need to be read by the service and written to a database.

Best Answer

This certainly sounds as if the account that your windows service is running under doesn't have enough rights to write to the event log in question.

Setting event log permissions for non-admin accounts can be a bit of a black art because you need to configure custom security descriptors using SDDL etc. However there's a very handy MS knowledgebase article on how to do this programmatically:

How to setup event log security programmatically using the .Net Framework

I use this all the time now and it's as simple as:

int mask = EventLogSecurity.CustomSD_ALL_ACCESS;

string logName = "Application";
string domain = "MyMachineOrDomainName";
string account = "UserAccount";

EventLogSecurity.AddUserToEventLogCustomSD(logName, domain, account, mask);