最终这与设置log4Net有关,但一般来说,问题不是具体记录.
通常我想知道的是在Microsoft Unity 2.0中如何做,相当于与Castle.Facilities.Logging.LoggingFacility相同的东西.也就是声明对记录器依赖的能力,并使记录器使用注入对象的类型进行初始化.
在测试的精神上值得一千字,这里是我需要的:
class Logger_IOC_Tests { //[Test] public void Logger_should_be_initialized_with_the_type_of_the_object_that_is_using_it() { var container = new UnityContainer(); /* Configuration Magic probably involiving registering either * a custom IDependencyResolverPolicy or BuilderStrategy * goes here... */ container.RegisterType<LoggerUser>(new ContainerControlledLifetimeManager()); var user = container.Resolve<LoggerUser>(); Assert.True(user.Logger.GetUserType() == user.GetType()); } } interface ILogger { Type GetUserType(); } class Logger : ILogger { private readonly Type _type; public Logger(Type type) { _type = type; } public Type GetUserType() { return _type; } } class LoggerUser { public readonly ILogger Logger; public LoggerUser(ILogger logger) { Logger = logger; } }
我不知道这是你正在寻找的,但我在几个月前看到它,当我看到你的问题时被提醒.我没有使用Unity,所以我不能真正比较你在链接上发布的内容.希望对您有用:
http://davidkeaveny.blogspot.com/2011/03/unity-and-log4net.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。