[英]How can i write to the windows event log using C# (I'm getting some kind of error)?
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. 我还启用了对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? 有人知道为什么会这样吗?
HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Services\\EventLog HKEY_LOCAL_MACHINE \\ System \\ CurrentControlSet \\ Services \\ EventLog
What is need to do was grant the " Security " sub key of the EventLog Key read permission. 需要做的是授予EventLog Key读取权限的“ Security ”子密钥。 After that i restarted my IIS.
之后,我重新启动了IIS。
如果您在要向其中写入事件日志的框上具有权限,则可以运行我编写的脚本 。
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.
如果您以管理员身份创建自己的PodaHIS源,则可能会发现它可以对其进行写入。
What it your deployment environment? 您的部署环境是什么? If it is Vista/Server 2008 then adding worker account into Administrators group won't work due to UAC.
如果是Vista / Server 2008,则由于UAC无法将工作人员帐户添加到Administrators组中。
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...
但我建议尝试手动创建事件源,以便ASPNET无需创建它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.