如何在log4net中保存名称为logger名称的日志文件? [英] How can I save log file whose name is logger name in log4net?
问题描述
在log4net中,我们可以使用ILog logger = LogManager.GetLogger(typeof(something));
创建记录器.
In log4net we can use ILog logger = LogManager.GetLogger(typeof(something));
to create logger.
但是我想在GetLogger()
方法中保存名称为"something"的日志.我怎样才能做到这一点?
But I want to save log with the name of "something" in GetLogger()
method. How can I do this?
推荐答案
log4net不支持此配置.如果只有几个类,则可以为每个类配置一个追加器,但是根据类的数量,您的配置文件会变得很大.
log4net does not support this by configuration. If you have only a few classes then you can configure an appender per class but depending on the number of classes your configuration file will get quite big.
您当然可以编写具有该功能的自己的附加程序,但是您可能想考虑改为登录数据库.这样,您可以按照自己认为合适的任何方式过滤日志消息.
You could of course write your own appender with that functionality but you may want to consider to do log to a database instead. This way you can filter your log messages in any way you see fit.
您还可以通过编程器为每个记录器创建附加程序.但是我不会去...
You could also create the appenders programmatically per logger. But I would not go for it...
这篇关于如何在log4net中保存名称为logger名称的日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!