2
使用c#編寫Windows事件日誌時出現問題。C#EventLog.WriteEntry對某些字符串失敗,但對其他字符串不成功
public static void writeToEventLog(string msgGrid, string msgIntern, EventLogEntryType entryType)
{
string grp = "Application"; // Fixed because cant create new but happy if bellow works.
if (!EventLog.SourceExists(msgGrid)) { EventLog.CreateEventSource(msgGrid, grp); }
EventLog.WriteEntry(msgGrid, msgIntern, entryType);
}
//如下因素代碼不放在事件日誌條目:
string msgGrid = "pdtidtijejrnexhr";
string msgIntern = "*-* [Dt:2013-10-31 11:41:10.00][digkufdufe:{[<2013-10-31 11:41:09> {jpdriskrt01} jpdriskrt01[172.22.3.70:57010]> [pdtidhry jrnecidr]]} : {}] >>#[eydshr:(rhrdhruiweirts.hrt.krt.krtjelr.jt.jpdrtjelkrhtw.<dnjr>b__1)]>>#[jpdrtjelkrhtw]\\[pdtidtijejrnexhr]\r\n";
writeToEventLog(msgGrid, msgIntern, EventLogEntryType.FailureAudit);
//如下因素代碼工作確定:
writeToEventLog("t1", "t2", EventLogEntryType.FailureAudit);
有一些關於日誌內容或大小的約束?
它是否是除外?你是否以同一用戶身份運行這兩個代碼片段? ('CreateEventSource()'只適用於需求特權) –
當你說「失敗」時,你是什麼意思? –
@Lynn Crumbling不,它不是,執行從Visual Studio 2010 C#4.0調試同樣的用戶。用管理員用戶執行Visual Studio。 – newway