我想在安全事件日志中写入这些值:
Console.WriteLine("Level: {0}", eventInstance.LevelDisplayName);
Console.WriteLine("Date: {0}", eventInstance.TimeCreated);
Console.WriteLine("Forrás: {0}", eventInstance.ProviderName);
Console.WriteLine("Event id: {0}", eventInstance.Id);
Console.WriteLine("Task: {0}", eventInstance.TaskDisplayName);
string sSource;
string sLog;
string sEvent;
sSource = eventInstance.ProviderName;
sLog = "Security";
sEvent = eventInstance.FormatDescription();
if (!EventLog.SourceExists(sSource))
EventLog.CreateEventSource(sSource, sLog);
EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, eventInstance.Id);
EventLog.WriteEntry(sSource, sEvent);
EventLog.WriteEntry(sSource, sEvent,
EventLogEntryType.Warning, eventInstance.Id);
我有一个例外这一行:
if (!EventLog.SourceExists(sSource))
例外:
无法打开源“安全”的日志。您可能没有写入权限。
但是当我将其更改Security
为另一个时,它可以工作,但只有应用程序事件日志包含这些值。