如何在dll中配置多个记录器
我是 log4net 的新手,当 dll 中有多个记录器时,我不太确定如何正确设置我的 app.config。嗯,我愿意,但我想知道当有 10-20 个不同的记录器时是否有更简单的方法。也可能是我不明白这一点。
好吧,假设 dll 使用以下记录器(实际上大约有 20 个这样的不同语句):
private static readonly ILog log = LogManager.GetLogger(typeof(XmlConfiguration));
private static readonly ILog log = LogManager.GetLogger(typeof(ClassValidator));
这是否意味着我需要在 app.config 中执行类似的操作(为了简洁起见,我省略了附加程序)?
<logger name="XmlConfiguration" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FileLog"/>
</logger>
<logger name="ClassValidator" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FileLog"/>
</logger>
我可以以某种方式配置它,以便特定 dll 或部分命名空间公开的每个记录器(dll 中的记录器位于几个不同的命名空间下,但具有公共根命名空间)都转到相同的日志记录源(文件、控制台等)吗?
I'm new to log4net and I'm not quite sure how to set up my app.config correctly when there are multiple loggers in a dll. Well I do but I'm wondering if there is an easier way when there are 10-20 different loggers. It may also be that I just don't understand this.
Ok so let's say the dll uses the following loggers (it's actually about 20 different statements like this):
private static readonly ILog log = LogManager.GetLogger(typeof(XmlConfiguration));
private static readonly ILog log = LogManager.GetLogger(typeof(ClassValidator));
Does this mean I need to do something like this in my app.config (I have omitted appenders for brevity)?
<logger name="XmlConfiguration" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FileLog"/>
</logger>
<logger name="ClassValidator" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="FileLog"/>
</logger>
Can I configure it somehow such that each logger exposed by a particular dll or partial namespace (loggers in dll are under several different namespaces but have a common root namespace) all go to the same logging source (file, console etc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你是对的。您可以通过配置多个记录器为不同的 dll 设置不同的登录级别:
这是我成功使用的示例:
Yes, you are correct. You can set different login levels for different dlls by configuring multiple loggers :
Here is an example i have used successfully :