将LogService添加到我的应用程序 [英] Adding LogService to my Application

查看:108
本文介绍了将LogService添加到我的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序(旧版代码)

包含带有`save()`方法的接口`Icomponent`

和许多实现它的类.

我想在每个save()之后添加日志.



我以为

将装饰器模式与其他`log()`方法一起用于`Icomponent`.

创建从每个装饰器的log()中调用的LogService类.
我认为LogService是singelton的经典案例,但我读过它很难进行单元测试.


I have an application (Legacy code)

that contains interface `Icomponent` with `save()` methods

and many classes that implement it.

I want to add log after every save().



I thought to

use the decorator pattern to `Icomponent` with additional `log()` method.

create `LogService` class which is called from each decorator''s `log()`

I think `LogService` is a classic case of singelton, but I read it would be hard for unit-testing.


What would be you design to that solution?

推荐答案

首先,请查看Apache log4net: ^ ].

我认为带有测井的装饰组件重量过大,如果刚性耦合,则太多.我将其用作可选功能,其中日志记录通常总是有用的.通常情况下,这不好.

如果方法更充分,则使用单例.我同意这将是单例使用的经典案例. 很难进行单元测试吗?"嗯我怀疑这只是某些人实际上没有进行单元测试的病态幻想的结果.我在这里看不到任何有关单元测试的特定问题.我可以想像我虽然错过了一些东西.在这种情况下,让这个人写信给我,解释一下那个硬度在哪里;我将不胜感激.

—SA
First of all, look at Apache log4net: http://logging.apache.org/log4net/[^].

I think decoration components with logging is too heavy weight and too much if stiff coupling. I would allow it for an optional feature where logging is often of always useful. In general case, this is no good.

The use of singleton if way more adequate. I would agree that this would be a classic case of singleton usage. "Hard for unit testing?" Hm. I suspect this is just a result of a sick fantasy of some person who does not actually do unit testing. I don''t see any specific problems for unit testing here. I can imagine that I''m missing something though. In this case, let this person write to me and explain where is that hardness; I would greatly appreciate it.

—SA


尝试:
Microsoft的企业库-记录应用程序块 [使用企业库进行日志记录 [
Try:
Microsoft''s Enterprise Library - Logging Application Block[^]
Get Logging with the Enterprise Library[^]


这篇关于将LogService添加到我的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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