事件日志WriteEntry不会写入日志指定,而是应用程序日志

编程入门 行业动态 更新时间:2024-10-24 01:53:29
本文介绍了事件日志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不会写入日志指定,而是应用程序日志

本文发布于:2023-11-11 07:53:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:日志   应用程序   事件   WriteEntry

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!