为什么 Log4Net 忽略我的 logName?
好的,我有一个 WCF 服务写入事件日志。
除了一个细节之外,一切都很好..它不会关注 logName 属性,..这是配置。
<!--EventLog Appender-->
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<logName value="MyCustomLog"/>
<applicationName value="MyCustomEventSource" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
..和初始化代码。
//Create an instance of the log from the declaring type.
var stackTrace = new StackTrace();
var frame = stackTrace.GetFrame(0);
log = LogManager.GetLogger(frame.GetMethod().DeclaringType);
BasicConfigurator.Configure();
事件日志确实被写入,但在应用程序日志中(使用 MyCustomEventSource“源)而不是我自己的日志。显然,我错过了一些重要的点,但我不知道那可能是什么......我正在运行Win 7 和 IIS 7.5 如果有任何差异,
我们将不胜感激。
Okay so I have a WCF service writing to the Event Log.
All is well except for one detail..it won't pay any attention to the logName attribute,..here's the config.
<!--EventLog Appender-->
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender" >
<logName value="MyCustomLog"/>
<applicationName value="MyCustomEventSource" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
..and the initialization code.
//Create an instance of the log from the declaring type.
var stackTrace = new StackTrace();
var frame = stackTrace.GetFrame(0);
log = LogManager.GetLogger(frame.GetMethod().DeclaringType);
BasicConfigurator.Configure();
The event log does get written to but in the Application log (using the MyCustomEventSource" source) rather than my own. Clearly I'm missing some important point but I don't see what that might be... I'm running on Win 7 and IIS 7.5 if that makes any diff.
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否创建了事件源 ?
我很惊讶您的代码可以工作:您需要使用
XmlConfigurator
。据我所知,BasicConfigurator 仅配置默认控制台记录器...也许还可以考虑创建这样的记录器(看起来更干净、更短):
Did you create an event source?
I am surprised that your code works: You need to use the
XmlConfigurator
. As far as I know theBasicConfigurator
only configures a default console logger...Maybe also consider to create the loggers like this (seems cleaner and shorter):