当需要记录时,会考虑哪种设计模式? [英] Which design pattern would you consider when Logging is needed?

查看:114
本文介绍了当需要记录时,会考虑哪种设计模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的应用程序需要记录操作,执行操作的用户以及对数据库的操作时间。

An application I'm working on requires logging of actions, user who performs the action, and time of action to a database.

哪种设计模式最受欢迎/适用于日志记录?

Which design pattern is most popular/appropriate for logging?

我正在考虑需要当前用户和操作的命令模式。执行操作并写入日志。

I'm thinking of Command pattern that require the current user and an action. Perform the action and write to the log.

你觉得怎么样?任何其他可以考虑的替代方案?

What do you think? Any other alternatives I can consider?

谢谢。

推荐答案

您可以使用 AOP 应用日志记录,而不会有任何侵入行为。
AOP可能会像Proxy和Decorator Pattern的混合。

You can use AOP to apply logging without any intrusive behavior. AOP may feel like a mixture of Proxy and Decorator Pattern.

这篇关于当需要记录时,会考虑哪种设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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