简体   繁体   English

无法写入事件日志

[英]Cannot write to the Event log

edI have C# ASP.NET 4.5 Webform application and use the following code: ed我拥有C#ASP.NET 4.5 Webform应用程序,并使用以下代码:

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

     EventLog.WriteEntry(sSource, message, level);

Since the first line was failing I created HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog\\Application\\IDDISLOG in registry 由于第一行失败,因此我在注册表中创建了HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ eventlog \\ Application \\ IDDISLOG

I get the following exception on WriteEntry Method: 我在WriteEntry方法上收到以下异常:

 Cannot open log for source 'IDDISLOG'. You may not have write access. 

Searched other similar questions but none worked for me. 搜索了其他类似问题,但没有一个对我有用。

Here is what I have done so far: 到目前为止,这是我所做的:

Added "Network service" to the project file folder 在项目文件夹中添加了“网络服务”

Added Network service to and gave it full access. 向中添加了Network service ,并为其提供了完全访问权限。 HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ eventlog

Added Nertwork service to and gave it full access. 向其添加了Nertwork服务,并为其提供了完全访问权限。

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security

Checked and saw w3wp.exe *32 process runs with User Name ASP.Net v4.0. 检查并看到w3wp.exe * 32进程以用户名ASP.Net v4.0运行。

So added ASP.Net v4.0 to 因此,将ASP.Net v4.0添加到

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog

Still, error remains 尽管如此,错误仍然存​​在

Your user account may not have sufficient privileges to create an event source, which only administrator accounts can do. 您的用户帐户可能没有足够的特权来创建事件源,只有管理员帐户才能这样做。 If you can log in as an administrator, either run your code again or add a folder here: HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\services\\eventlog\\Application\\IDDISLOG 如果您可以管理员身份登录,请再次运行代码或在此处添加文件夹:HKEY_LOCAL_MACHINE \\ SYSTEM \\ CurrentControlSet \\ services \\ eventlog \\ Application \\ IDDISLOG

That should allow your application to write to the event log with that source. 那应该允许您的应用程序使用该源写入事件日志。 You may need to configure the actual registry entry further to suit your needs. 您可能需要进一步配置实际的注册表项,以满足您的需求。

In IIS (Windows server), you should change de identity used by de app pool, so the new identity has permission to write to the event log. 在IIS(Windows服务器)中,您应该更改应用程序池使用的身份标识,因此新身份具有写入事件日志的权限。 Select the app pool and advanced settings. 选择应用程序池和高级设置。 then edit and insert a custom account, althoug local system will suffice. 然后编辑并插入自定义帐户,althoug本地系统就足够了。 If you use a custom account be sure not to use a user whose password is going to expire, because when it happens logging to event log will fail. 如果使用自定义帐户,请确保不要使用密码将要过期的用户,因为发生这种情况时,登录事件日志将失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM