为 log4net 中类的每个实例创建日志的最佳方法是什么?
我们有几个长期存在的对象,每个对象都在系统中属于同一类。大约只有 5 或 6 个,它们是与外部系统的连接。我希望每个实例都有自己可以登录的文件。
最好的方法是什么?我现在只能看到以编程方式添加记录器作为答案。
更新: 我想避免使用配置文件,因为如果我向不同的远程主机添加新连接,那么我希望其日志输出转到以连接命名的文件,而不必首先在配置文件中进行修改。如果能自动完成就好了。我不知道这是否可以在配置文件中一次性实现,并且您不需要每次都编辑它。
We have a couple of long lived objects each of the same class in the system. There are only about 5 or 6 and they are connections to outside systems. I want each of those instances to have their own file that they can log to.
What is the best way to do this? I can only see adding loggers programatically as the answer right now.
UPDATE:
I want to avoid using the configuration file because if I add a new connection to a different remote host then i want its log output to go to file named after the connection without having to first hack around in a config file. It would be nice if it was done automagically. I don't know maybe this can be achieved in a config file once off and that you don't need to edit it everytime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
最好的答案是编程日志记录,我遇到了同样的问题,并发现它是唯一的解决方案。
如需更多帮助,请检查此问题(我的)
我发布的 StackOverFlow 问题
和我认为你的问题和我的问题是一样的,动态记录器,重新创建记录器,在运行时处理记录器和所有这些东西:)
如果还有任何问题,请询问,我很乐意提供帮助,因为我已经完成了所有这些:)
The best answer IS programatical logging, i went through the same problem and found it as the only solution.
For more help check this question (mine)
StackOverFlow Question posted by me
and i thing yours and my problem are the same, dynamic loggers, re create loggers, dispose loggers and all that stuff at runtime :)
if any more questions, do ask, will be glad to help since i have gone through all that :)
我实际上可以看到几种可能性:
I can actually see a couple of possibilities:
我有一篇文章可能会有所帮助:
http://horth.com/blog/?p=165
这是关于在运行时更改日志文件。您可以做的是将每个实例的文件名传递到 log4net 文件中。这样您就可以为类的每个实例创建一个日志文件。
至于您不想使用配置文件的编辑,此方法可以解决该问题,以便您可以使用配置文件,但仍然具有所需的灵活性。
I have an article that might help:
http://horth.com/blog/?p=165
This is about changing a logfile at runtime. What you could do is pass in the file name for each instance into your log4net file. That way you could create a log file for each instance of your class.
As for your edit about not wanting to use a config file, this method gets around that issue so that you can use a config file but still have the flexibility you want.