C# EventLog.WriteEntry 对某些字符串失败但对其他字符串则不会

标签 c# event-log

使用 C# 写入 Windows 事件日志时出现问题。

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);

日志内容或大小有一些限制吗?

最佳答案

看起来您的来源(“pdtidtijejrnexhr”)尚不存在,但“t1”存在,所以这就是其他代码片段有效的原因。此外,您可能需要加倍使用大括号({}),但我对此并不肯定。 (分别为 {{}})。

我不认为“t1”默认情况下随 Windows 一起提供。我怀疑您的代码曾经成功地创建了它(可能与您没有在日志消息?)

关于C# EventLog.WriteEntry 对某些字符串失败但对其他字符串则不会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19708887/

相关文章:

biztalk - 从 BizTalk 写入事件日志

c# - 我们如何使用 LINQ 从 asp.net mvc3 中的长字符串中提取短字符串?

c# - 在 sql 和 web 应用程序之间发送安全密码的最佳实践?

c# - 在 C# 4 中,如何在具有重载构造函数的父类的子类中拥有带可选参数的构造函数?

c# - 在 Windows 7 事件日志中,什么是 "Source"?

c# - foreach over Hashtable 在第一个键上停止

C# 停止按钮在单击时获得焦点

c# - 如何播放要在设定的延迟下重复播放的音频片段阵列?

wmi - 什么是 win32_NTLogEvent 时间生成格式

c# - 远程 Windows 事件记录 - 授权