1
我想在安全事件日誌寫這些值:如何將日誌寫入安全事件登錄C#?
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
更改爲另一個時,它可以正常工作,但只是應用程序事件日誌包含這些值。
對不起,最後3行是該代碼的兩倍。 – user1520209 2012-08-03 10:39:30