本文介绍了事件日志WriteEntry不会写入日志指定,而是应用程序日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我想B上的记录器通过MEF实例编写条目事件日志$ B $的应用程序。 我创建了一个派生类,要能先用它来执行日志初始化
I have an application where I want to write entries to event log The logger is instantiated through MEF. I created a derived class, to be able to perform the log initializations prior of using it.
我的代码如下:
public class WinEventLog : EventLog, ILogger { private const string LOG_SourceName = "DataGen_Source"; private const string LOG_SysLogName = "Pool_Log"; private bool _isInitialized = false; public WinEventLog() : base() { Initialize(); } public void LogMessage(MessageLevel level, string message) { WriteEntry(message, level.EventLogType()); } public void LogMessage(string source, MessageLevel level, string message) { WriteEntry(source, message, level.EventLogType()); } public void Initialize() { if (!_isInitialized) { this.BeginInit(); this.EndInit(); if (!System.Diagnostics.EventLog.SourceExists(LOG_SourceName)) { System.Diagnostics.EventLog.CreateEventSource( LOG_SourceName, LOG_SysLogName); } Source = LOG_SourceName; Log = LOG_SysLogName; _isInitialized = true; } } }
然而,logger不写入到我指定,Pool_Log日志,但在应用程序日志中。
However, the logger does not write into the log I specify, Pool_Log, but in Applications log.
任何想法,为什么出现这种情况?
Any idea why this happens?
修改
我EXACT引用从其他项目相同的成分,在这种情况下,它写道:正确的事件日志!
I referenced EXACT the same component from other project, and in this situation it wrote to the correct EventLog !!!
我明白!
感谢
推荐答案您可以尝试以下方法:
evntSource = "MySource"; evntLog = "MyLog"; //This replace Application! evntEvent = "My Event"; if (!EventLog.SourceExists(evntSource)) EventLog.CreateEventSource(evntSource,evntLog); EventLog.WriteEntry(evntSource,evntEvent);更多推荐
事件日志WriteEntry不会写入日志指定,而是应用程序日志
发布评论