2017-06-14 158 views
0

我嘗試寫新日誌MyLog但它總是寫入應用程序日誌(登錄Windows)無法事件日誌寫入指定的日誌

string sSource; 
string sLog; 
sSource = "MySource"; 
sLog = "MyLog"; 
if (!EventLog.SourceExists(sSource)) 
    EventLog.CreateEventSource(sSource, sLog); 
using (EventLog eventLog = new EventLog(sLog)) 
{ 
    eventLog.Source = sSource; 
    eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101, 1); 
} 

我試圖刪除註冊表中的日誌條目重新創建日誌但問題仍然存在。

有任何幫助。

回答

0

我使用幾乎相同的代碼,有兩個區別。我手動設置日誌未在構造函數中,我不給上WriteEntry方法的類別:

string sSource; 
    string sLog; 
    sSource = "MySource"; 
    sLog = "MyLog"; 
    if (!EventLog.SourceExists(sSource)) 
     EventLog.CreateEventSource(sSource, sLog); 
    using (EventLog eventLog = new EventLog()) 
    { 
     eventLog.Source = sSource; 
     eventLog.Log = sLog; 
     eventLog.WriteEntry("Log message example", EventLogEntryType.Information, 101); 
    } 
+0

它劇照保存到應用程序日誌,真的很奇怪。 –

+1

有人有一個simmilar問題在這裏:https://stackoverflow.com/questions/31114998/eventlog-logs-in-application-even-though-set-to-another-log –

+0

謝謝,我必須重新啓動機器才能獲得它重新映射。真的很混亂的系統。 –