我所有的代碼工作正常了這一點:達代碼,不執行和退出沒有錯誤
using System.Diagnostics;
namespace WebPortalLogging
{
public static class EventLogging
{
public static void LogEvent(string origin, string message, EventLogEntryType eventLogEntryType, int eventId)
{
const string source = "Software";
const string log = "Application";
if (!EventLog.SourceExists(source))
EventLog.CreateEventSource(source, log);
EventLog.WriteEntry(source, message, eventLogEntryType, eventId);
}
}
}
我甚至在另一個項目中使用這個類,它工作正常。當它碰到這一行時:
if(!EventLog.SourceExists(source)) EventLog.CreateEventSource(source,log);
它擊中此線並退出。
這裏是什麼在我的輸出:
The thread 'vshost.NotifyLoad' (0x28c) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x470) has exited with code 0 (0x0).
'VmBackup.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Google Drive\Code\VMBackup\VMBackup\bin\Debug\VmBackup.exe', Symbols loaded.
'VmBackup.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Google Drive\Code\VMBackup\VMBackup\bin\Debug\WebPortalLogging.dll', Symbols loaded.
The thread '<No Name>' (0xa44) has exited with code 0 (0x0).
'VmBackup.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
The thread '<No Name>' (0x107c) has exited with code 0 (0x0).
The thread '<No Name>' (0x1838) has exited with code 0 (0x0).
The thread 'vshost.RunParkingWindow' (0xa78) has exited with code 0 (0x0).
The thread '<No Name>' (0x10e0) has exited with code 0 (0x0).
The program '[6436] VmBackup.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[6436] VmBackup.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
它沒有達到EventLog.WriteEntry。它也不會輸出到事件日誌中。我已經重新啓動VS2010,並沒有幫助。我提示所有打開的錯誤。
我錯過了什麼?
好點,我會給你一個鏡頭。 – ErocM
用於大括號。如果在我的寵物小偷列表中沒有格式化的sql語句,那麼無情的。 –
我做了兩個,它沒有區別。我沒有發現錯誤。我正在退出「if(!EventLog.SourceExists(source))」並且它不會再繼續。 – ErocM