如何包装项目每个功能? [英] How to wrap each function in project?

查看:140
本文介绍了如何包装项目每个功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经吨的功能在我的WinForms项目,我用NLOG进行记录。我想有包装与每个功能nlogger.Info(开始) nlogger.Info(结束),所以我会知道在哪个地方发生实际的异常或code目前正在运行的地方。

I have tons of functions in my WinForms project and i'm using NLog for logging. I want to have an ability to wrap each function with nlogger.Info("start") and nlogger.Info("end") so i will know in which place actual exception occurred or where the code currently runs.

有一个聪明的办法做到这一点还是我需要从上面放置线我所有的功能?

Is there a smart way to do it or i will need to place lines from above in all of my functions ?

推荐答案

我相信 PostSharp 可以做到这一点为你,并且可以应用在组件级别(通过程序集级别的属性)。不过,我会很谨慎的潜在的性能影响。编写方面应该是pretty的很少。

I believe that PostSharp can do this for you, and can apply at the assembly level (via assembly-level attributes). However, I would be cautious of the potential performance impact. Writing the "aspect" should be pretty minimal.

这篇关于如何包装项目每个功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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