我尝试将新日志写入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);
}
我尝试删除Registry上的日志条目以重新创建日志,但问题仍然存在。
任何帮助。
答案 0 :(得分: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);
}