PostSharp - il 编织 - 想法
我正在考虑使用 Postsharp 框架来减轻应用程序方法日志记录的负担。 它基本上允许我用日志记录属性装饰方法,并在编译时将所需的日志记录代码注入 il. 我喜欢这个解决方案,因为它可以将噪音排除在设计时间代码环境之外。 有什么想法、经验或更好的选择吗?
I am considering using Postsharp framework to ease the burden of application method logging.
It basically allows me to adorn methods with logging attribute and at compile time injects the logging code needed into the il. I like this solution as it keeps the noise out of the deign time code environment.
Any thoughts, experiences or better alternatives?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这在一定程度上取决于您将开发和支持该项目多长时间。 当然,IL 编织是一项很好的技术,但是如果 IL 和/或程序集元数据格式再次发生更改(如 1.1 和 2.0 之间的情况)并且这些更改使工具与新格式不兼容,会发生什么情况。
如果您依赖该工具,那么它会阻止您升级技术,直到该工具支持它。 由于对此没有任何保证(甚至开发将继续,尽管看起来确实有可能),那么我对在长期项目中使用它会非常谨慎。
短期来看,没问题。
It depends to an extent on how long you'll be developing and supporting the project for. Sure, IL weaving is a nice technology, but what happens if the IL and/or assembly metadata format changes again (as it did between 1.1 and 2.0) and those changes make the tool incompatible with the new format.
If you depend on the tool then it prevents you from upgrading your technology until the tool supports it. With no guarantees in place about this (or even that development will continue, though it does seem likely) then I'd be very wary about using it on a long term project.
Short term, no problem though.
我使用 Castle Windsor DynamicProxies 通过 AOP 来应用日志记录。 我已经在使用 Castle 作为 IoC 容器,因此将它用于 AOP 对我来说是阻力最小的路径。 如果您想要更多信息,请告诉我,我正在整理代码,以便将其作为博客文章发布
编辑
好的,这是基本的拦截器代码,虽然基本失败,但它可以满足我需要的一切。 有两个拦截器,一个记录所有内容,另一个允许您定义方法名称以允许更细粒度的日志记录。 此解决方案失败依赖于 Castle Windsor
抽象基类
完整日志记录实现
方法日志记录
I apply logging with AOP using Castle Windsor DynamicProxies. I was already using Castle for it's IoC container, so using it for AOP was the path of least resistence for me. If you want more info let me know, I'm in the process of tidying the code up for releasing it as a blog post
Edit
Ok, here's the basic Intercepter code, faily basic but it does everything I need. There are two intercepters, one logs everyhing and the other allows you to define method names to allow for more fine grained logging. This solution is faily dependant on Castle Windsor
Abstract Base class
Full Logging Implemnetation
Method logging
+1 后锐利。 已经用于多种用途(包括一些向 C# 代码添加前置条件和后置条件的尝试),并且不知道如果没有它我将如何实现......
+1 on postsharp. Have been using for several things (including some attempts on adding preconditions and postconditions to C# code) and don't know how I'd make it without it...