在 VSTO 中配置 log4net
我已将 VSTO Excel 加载项设置为使用 log4net 进行日志记录。不幸的是,我(似乎)无法使其从 app.config(我通过 ClickOnce 与加载项一起提供)进行自身配置。
我已阅读 http://www.darinhiggins.com/?p=13 其中列出有一些方法可以获取 app.config 的文件名,然后使用以下方法配置 log4net
log4net.Config.XmlConfigurator.Configure(fileInfo)
但是,此博客列出的方法对我来说似乎很容易出错(它们“闻起来很糟糕”)。
诸如此类的事情
ConfigurationManager.GetSection
让我相信 .NET 框架确切地知道从哪里获取文件,并且必须有一种方法可以从框架中检索此信息,而不必自己弄清楚。但是,XmlConfigurator
依次只接受文件名、流或 xml 节点...
(为什么我认为它目前不起作用:我已将其配置为使用 RollingFileAppender 和文件名为 H:\Data\Debug.log,但在 GetLogger(...).Debug(...)
之后,仍然没有 Debug.log ...)。我在其他地方使用了完全相同的配置,成功了。
I've set up my VSTO Excel add-in to use log4net for logging. Unfortunately I'm (seemingly) not able to make it configure itself from the app.config (which I deliver together with the add-in via ClickOnce).
I have read http://www.darinhiggins.com/?p=13 which lists some ways to get the file name of the app.config and then configure log4net with
log4net.Config.XmlConfigurator.Configure(fileInfo)
However the approaches this blog lists seem very error-prone to me (they "smell bad").
Things like
ConfigurationManager.GetSection
make me believe the .NET framework knows exactly where to get the file and there must be a way to retrieve this information from the framework instead of having to figure it out on my own. However, the XmlConfigurator
in turn only accepts a file name, stream or xml node...
(Why I believe it's not working at the moment: I have configured it to use a RollingFileAppender with the file name being H:\Data\Debug.log, but after a GetLogger(...).Debug(...)
, there is still no Debug.log in place...). I have used the exact same configuration in other places, successfully.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XmlConfigurator.Configure();
使用 app.config 文件。这应该可以工作,因为 ConfigurationManager 似乎能够读取配置文件。XmlConfigurator.Configure();
uses the app.config file. That should work since the ConfigurationManager seems to be able to read the config file.