4

After 3 hours of getting this message "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security."

and trying several solutions, I am posting here. Is there a concise way to write to an event log from the WebService (asmx) running on my localhost?

I followed the instructions found on msdn and added NETWORK SERVICE using regedit, giving it read rights as per http://social.msdn.microsoft.com/Forums/en-US/windowsgeneraldevelopmentissues/thread/416098a4-4183-4711-a53b-e10966c9801d/

Here is my code inside my Web Service

    string sSource = "MyWebService";
    string sLog = "Application";
    string sEvent = "Sample Event";            

    if (!EventLog.SourceExists(sSource))
        EventLog.CreateEventSource(sSource, sLog);

    EventLog.WriteEntry(sSource, sEvent);
    EventLog.WriteEntry(sSource, sEvent,
        EventLogEntryType.Error, 234);

1 Answer 1

4

The windows account that your web service runs as (might be Network Service or something completely different, depending on configuration) needs to have the "Manage auditing and security log" right in order to be able to create new event log sources. You can assign this right in Local Security Policy > Local Policies > User Rights Assignment.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi acezanne, Im still getting same error has "The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security". Even though i set same permission you told in the above step. If i run application as "run as administrator" i dont get any errors.
Yes, I used this successfully for many years but I'm afraid that due to some changes in Windows and/or .NET this solution doesn't really work anymore. I have not yet found a solution for Win7/.NET 4 other than making the account an admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.