温莎城堡的内部日志 [英] Internal logs for Castle Windsor

查看:75
本文介绍了温莎城堡的内部日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何记录温莎城堡的内部日志?例如,如果我以无法加载连接字符串的方式对Castle进行了错误配置,我想知道当Castle尝试解析连接字符串时是否可以记录来自Castle的错误.我正在使用Log4Net工具,但只能查看应用程序日志,而不能查看Windsor日志.

How can I log Castle Windsor internal logs? For example if I had misconfigured Castle in a way that is failing to load the connection string, I want to know if I can log the errors from Castle when it tries to resolve the connection string. I'm using Log4Net Facility and I'm only able to see application logs, not Windsor logs.

推荐答案

如果解析失败,则您对WindsorContainer.Resolve<>的调用将引发异常.您应该在负责创建容器和解决所需组件的引导"代码中记录此异常.异常消息通常会告诉您确切的错误原因.

Your call to WindsorContainer.Resolve<> will throw an exception if the resolution fails. You should log this exception in your "bootstrapping" code that is responsible for creating the container and resolving the needed component(s). The exception message typically tells you exactly what is wrong in excruciating detail.

据我所知,Windsor不会通过log4net进行任何内部"日志记录(也许其中一个贡献者可以对此进行纠正/确认).如果希望记录内部"事件,则可以连接内核上的事件处理程序(可通过WindsorContainer.Kernel访问).例如,有ComponentRegistered和DependencyResolving事件,它们使您可以分别对注册和解决方案执行自定义操作.

To my knowledge, Windsor does not do any "internal" logging via log4net (perhaps one of the contributors can correct/affirm this). If you wish to log "internal" events, you can hook up to the event handlers on the kernel (accessible via WindsorContainer.Kernel). For example, there are ComponentRegistered and DependencyResolving events that allow you to take custom action on registrations and resolutions, respectively.

这篇关于温莎城堡的内部日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆