2010-08-24 80 views
2

我爲我的Windows服務使用自定義EventLog。該服務在安裝後創建事件源。我沒有任何問題。Windows服務始終寫入自定義日誌和應用程序日誌

不過,我安裝我的服務,這樣我可以從IDE使用下面的機制運行它:

static void Main(string[] args) 
{ 
    AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledException); 

    string firstArgument = string.Empty; 

    if (args.Length > 0) 
     firstArgument = args[0].ToUpperInvariant(); 

    if (string.Compare(firstArgument, "-CONSOLE", true) == 0) 
    { 
     new SchedulerService().RunConsole(args); 
    } 
    else 
    { 
     ServiceBase[] services = new ServiceBase[] { new SchedulerService() }; 
     ServiceBase.Run(services); 
    } 
} 

當寫入事件日誌,它似乎寫我的自定義事件日誌和應用程序登錄。我怎樣才能防止這種情況發生?

下面是我使用寫入事件日誌代碼:(事件日誌的應用程序設置爲源和名稱相同)

using (System.Diagnostics.EventLog eventLog = 
    new EventLog(
     System.Configuration.ConfigurationManager.AppSettings["EventLog"], ".", 
     System.Configuration.ConfigurationManager.AppSettings["EventLog"])) 
{ 
    eventLog.WriteEntry(msg, entryType); 
} 

回答

2

看來,我的機器重新啓動已經修復了這個問題。我不確定爲什麼,但是我將假設事件查看器機制進入某種奇怪的狀態。

相關問題