How can i write to the windows event log using C# (I'm getting some kind of error)?

…衆ロ難τιáo~ 提交于 2019-12-08 04:20:03

问题


I have written:

.
.
.
//Log exception to the event log
if (!EventLog.SourceExists("PodaHIS")) {
    EventLog.CreateEventSource("PodaHIS", "Application");   
}

EventLog eventLog = new EventLog();
eventLog.Log = "Application";
eventLog.Source = "PodaHIS";
eventLog.WriteEntry(error.ToString(), EventLogEntryType.Error);

I have also enabled read permission to LOCALMACHINE\ASPNET.

And in return i get:

The source was not found, but some or all event logs could not be searched. Inaccesible logs: Security.

Does anyone know why this is happening?


回答1:


HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog

What is need to do was grant the "Security" sub key of the EventLog Key read permission. After that i restarted my IIS.




回答2:


this kb artical explains the steps required to give your asp process the correct security rights to write to the event log...

kb




回答3:


If you have permission on the box that you want to write the event log to, then you can run a script that I wrote.




回答4:


I think that a higher level of access is required to create a source in the event log. It's possible that the reference to Security log is coincidental and it is just reporting that as a possible cause. If you go in as an administrator and create the PodaHIS source yourself, you might then find that it can write to it.




回答5:


What it your deployment environment? If it is Vista/Server 2008 then adding worker account into Administrators group won't work due to UAC.

This link explains the problem in details. But I would recommend try creating an event source manually so ASPNET won't need to create it...



来源:https://stackoverflow.com/questions/1906077/how-can-i-write-to-the-windows-event-log-using-c-sharp-im-getting-some-kind-of

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!