BHO 内的 Log4net 不起作用?
我正在尝试将 log4net 与外部配置文件一起使用,但它不起作用:没有记录任何内容
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\\tmp\\test.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref="RollingFile" />
</root>
</log4net>
如果我在 Assembly.cs 中使用此行,则在使用 regasm 注册 BHO 时会创建 test.lg,但在插件时不会创建 test.lg正在运行:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = @"C:\\tmp\\test.log4net", Watch = true)]
当我在 BHO 中使用此代码时,没有日志添加到 test.log:
XmlConfigurator.Configure(new System.IO.FileInfo(@"C:\\tmp\\test.log4net"));
log.Info("test");
我不确定我做错了什么。
I'm trying to use log4net with an external config file, but it does not work: nothing gets logged
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\\tmp\\test.log" />
<appendToFile value="true" />
<maximumFileSize value="100KB" />
<maxSizeRollBackups value="2" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level %thread %logger - %message%newline" />
</layout>
</appender>
<root>
<appender-ref ref="RollingFile" />
</root>
</log4net>
If I use this line in Assembly.cs, test.lg is creatd when the BHO is registered with regasm, but not when the plugin is running:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = @"C:\\tmp\\test.log4net", Watch = true)]
When I use this code inside the BHO, no log is adde to test.log:
XmlConfigurator.Configure(new System.IO.FileInfo(@"C:\\tmp\\test.log4net"));
log.Info("test");
I'm not sure what I am doing wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
log4net 配置文件没问题。问题在于 Internet Explorer 在保护模式下运行,该模式禁止 BHO 写入任意文件夹。 BHO 只能写入几个文件夹。
The log4net configuration file was fine. The problem is that Internet Explorer ran in Protected Mode, which forbids BHOs to write to arbitrary folders. There are only a few folders where the BHO can write.