共享相关ID与Castle(Windsor)LoggingFacility

时间:2013-09-13 00:37:17

标签: c# wcf log4net castle-windsor castle

我正在使用Castle Windsor和Log4Net,我希望在不同的服务之间共享“相关ID”(每个事务/ WCF调用)。 理想情况下,这甚至会跨越WCF事务(客户端上的单击会生成ID,然后在服务器上重复使用)。

看起来IExtendedLogger及其ThreadProperties是可行的方法,但我该如何设置呢? 有没有比创建自己的ILoggerFactory和创建ThreadProperties更好的方法? (顺便说一下,服务的不同LifeStyle设置是否会破坏机制?)

遗憾的是,文档真的很稀疏...... :(

我的目标是我的日志看起来像这样:

1111-1111-1111-1111 INFO OrderService: Processing order with ID 8765
8888-8888-8888-8888 INFO CustomerService: Updating address for customer with ID 9999
1111-1111-1111-1111 INFO OrderRepository: Loading order with ID 1234
1111-1111-1111-1111 INFO CustomerRepository: Loading customer with ID 2222
8888-8888-8888-8888 INFO CustomerRepository: Loading customer with ID 2222
...

所以这将是两个不同的事务(OrderService和CustomerService中的入口点),即使两者都使用CustomerRepository(依赖),也会保留上下文,以便很容易看到哪个日志消息属于哪个呼叫/交易。

0 个答案:

没有答案