【发布时间】:2020-08-13 10:33:40
【问题描述】:
我有一个在 2016 Windows Server v1607 上的事件日志中创建新事件源的应用程序。目前尚不清楚消息来源将拥有哪些名称。要存档此帐户需要对所有事件源的读取权限,以确保源名称不存在(为什么不允许不同日志中的双重源名称是另一个有趣的问题)。默认情况下,本地帐户被阻止读取安全事件日志,因此创建新源最终会出现错误,即没有对安全日志的读取权限。
最有希望的方法似乎是这个问题的答案:https://stackoverflow.com/a/3138269/2091030
我按照步骤 1-5 通过添加本地帐户的读取权限来更改 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security 的注册表权限。我检查了安全文件夹中的所有子密钥,它们都显示了该帐户的正确读取权限。尽管如此,当使用简单的 C# 程序添加具有新源的事件时,我现在又遇到了另一个错误:
using System;
using System.Diagnostics;
namespace EventlogTest {
public class Test {
public static void Main() {
var log = new EventLog("SomeLog", ".", "SomeNewSource");
log.WriteEntry("Test 123", EventLogEntryType.Information);
}
}
}
System.Security.SecurityException: Der angeforderte Registrierungszugriff ist unzulässig.
bei System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
bei Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
bei System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
bei System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName, String currentMachineName)
bei System.Diagnostics.EventLogInternal.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
bei System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type)
bei EventlogTest.Test.Main()
我错过了什么吗?
【问题讨论】:
-
尝试将写入权限添加到应用程序(不是安全)事件日志。
-
我找到了正确的设置,请参阅下面的答案。本地帐户需要为整个 Eventlog 文件夹“设置值”和“创建子项”并不明显。
标签: c# registry event-log windows-server