繁体   English   中英

无法将事件日志写入指定的日志

[英]Cannot write event log to the designated log

我尝试将新日志写入MyLog,但它始终写入应用程序日志(Windows Log)

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

我试图删除注册表上的日志条目以重新创建日志,但问题仍然存在。

帮忙。

我使用几乎相同的代码,但有两个区别。 我没有在构造函数中手动设置日志,并且没有在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);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM