Writing to Application Log in Event Viewer
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 sEv开发者_开发百科ent = "Sample Event";
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Error, 234);
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.
精彩评论