问题描述
我收到错误:
当我运行下面的代码来捕获Win 2K12 R2服务器上的错误IIS 8.5
When I run below code to capture errors on Win 2K12 R2 server IIS 8.5
EventLog elog = new EventLog();
EventLog.CreateEventSource("MyApp", "Application");
EventLog.WriteEntry(Source, swError.ToString(), EventLogEntryType.Error);
我已经完全访问 HKLM \SYSTEM \ CurrentControlSet \\ \\services\eventlog
但它仍然没有工作。我该怎么做才能解决它?
I've given full access to HKLM\SYSTEM\CurrentControlSet\services\eventlog
but it is not working still. What shall I do to fix it?
推荐答案
参见 。
此问题不仅可能由于权限而发生,还可能由于事件源密钥丢失而导致未成功注册(您需要管理员权限才能执行此操作)如果您像往常一样打开Visual Studio并正常运行程序,那就不够了)。确保您的事件源MyApp实际已注册,即它出现在注册表中的 HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet \ services \eventlog \ Application
。
This problem can occur not only due to permissions, but also due to event source key missing because it wasn't registered successfully (you need admin privileges to do it - if you just open Visual Studio as usual and run the program normally it won't be enough). Make sure that your event source "MyApp" is actually registered, i.e. that it appears in the registry under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application
.
来自:
因此您必须以管理员身份运行事件源注册码(另外,检查源是否已经存在 - 请参阅上面的MSDN示例)或者您可以手动将密钥添加到注册表中:
So you must either run the event source registration code as an admin (also, check if the source already exists before - see the above MSDN example) or you can manually add the key to the registry:
- 创建一个regkey
HKEY_LOCAL_MACHINE \SYSTEM\CurrentControlSet \services \eventlog \ Application \ MyApp
; - inside,create字符串值
事件MessageFile
并将其值设置为例如C:\ Windows \ Microsoftoft.NET\Framework\v2.0.50727\EventLogMessages.dll
- create a regkey
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Application\MyApp
; - inside, create a string value
EventMessageFile
and set its value to e.g.C:\Windows\Microsoft.NET\Framework\v2.0.50727\EventLogMessages.dll
这篇关于找不到源,但无法搜索部分或全部事件日志。无法访问的日志:安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!