log4net:拒绝记录除特定组件之外的其他组件
假设您正在使用一些内部使用 log4net 的库,例如 NHibernate 或 Castle ActiveRecord。您的应用程序也使用 log4net。可以配置所有应用程序将日志保存到文件或任何其他输出中。但问题是,通过为我自己的应用程序启用 log4net,其他程序会将其日志保存到日志文件中,并导致其增长速度非常快,其中包含我目前不需要的信息。
如何将每个应用程序的日志路由到不同的输出,或者至少如何拒绝其他应用程序进行日志记录?
Assume you are using some libraries like NHibernate or Castle ActiveRecord that use log4net internally. Your application uses log4net too. It's possible to configure all applications to save logs into file or any other output. But the problem is by enabling log4net for my own application, other programs save their log into the log file and causes it grow very fast with information that I don't need at the moment.
How can I route logs of each application to different outputs or at least how can I deny other applications from logging?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NHibernate/Castle Active Record 生成大量日志信息,但这都是调试级别的日志记录。因此,您可以在配置文件中将日志级别从“ALL”降低到“INFO”或“ERROR”,应该没问题。
log4Net 还支持命名记录器和记录器层次结构。我确信 NHibernate/Castle 都会使用命名记录器。因此,您可以选择使用配置忽略该特定的命名记录器。请参阅 log4Net 帮助,其中他们使用了不同的 Com 日志记录级别。福图书馆.
使用命名记录器是将日志跟踪与不同组件/模块/库等分离的典型方法。每个应用程序(如在不同的进程中)将具有不同的配置文件,并且您始终可以使用不同的日志文件来分离日志跟踪。
NHibernate/Castle Active Record generate lot of log information but that is all DEBUG level logging. So you can turn down your log level from "ALL" to "INFO" or "ERROR" in config file and you should be OK.
log4Net also support named logger and logger hierarchy. I am sure both NHibernate/Castle would be using named logger. So you can choose to ignore that particular named logger using configuration. See log4Net help where they have used have different logging level for Com.Foo library.
Using named logger is a typical way of separating log traces from different components/modules/libraries etc. Each application (as in different process) would have different configuration file and you can always have different log files to separate the log traces.
只需将不同的记录器定向到不同的附加程序即可。
伪示例:
Just direct different loggers to different appenders.
Pseudo example: