记录类 - 实例或静态 [英] Logging Class - Instance or Static
问题描述
我有一个日志记录组件,我将在其他程序集中访问。所以我告诉我,我应该将一个实例传递给这些组件
而不仅仅是使日志记录类保持静态。如果我让它静止我就不需要
传递一个实例。你对此有何看法?
I have a logging component that I will access in other assemblies. So it was
brought up to me that I should pass an instance around to these components
instead of just making the logging class static. If I make it static I
wouldn''t need to
pass an instance around. What is your take on this?
推荐答案
JJ写道:
JJ wrote:
我有一个我将在其他程序集中访问的日志记录组件。所以它向我提出了
我应该将一个实例传递给这些
组件,而不仅仅是使日志记录类静态。如果我这样做,那么
静态我不需要
传递一个实例。你对此有什么看法?
I have a logging component that I will access in other assemblies. So it
was brought up to me that I should pass an instance around to these
components instead of just making the logging class static. If I make it
static I wouldn''t need to
pass an instance around. What is your take on this?
一个重要的决定,这取决于你的需求。你的班级需要
来保留州吗?这有多复杂?如何记忆饥渴?
-
Tom Spink
爱丁堡大学
Hi,
An important decision, and it depends on your needs. Does your class need
to retain state? How complicated is it? How memory-hungry is it?
--
Tom Spink
University of Edinburgh
它是一个非常简单的类,它将发送电子邮件,写入事件日志或
文件。我的想法是,如果我传递一个实例并且它传递了一个大约3个类的
链,那么我将有多个refs到我的日志类
我想知道如果这是在这里使用的正确编码技术?
Its a pretty simple class that will send emails, write to eventlog or to a
file. My thinking is if I pass an instance around and it gets passed down a
chain of about 3 classes then I will have multiple refs to my logging class
and I am wondering if that is the proper coding technique to be using here?
您的班级是否需要
来保留州?
Does your class need
to retain state?
我的班级不需要保留状态但是如果我让它静止我可以直接从任何地方参考
没有参考。
Tom Spink写道:
No my class doesn''t need to retain state but if I make it static I can just
refer to directly from any where without having refs to it.
"Tom Spink" wrote:
JJ写道:
JJ wrote:
我有一个日志组件,我将在其他程序集中访问。所以它向我提出了
我应该将一个实例传递给这些
组件,而不仅仅是使日志记录类静态。如果我这样做,那么
静态我不需要
传递一个实例。你对此有什么看法?
I have a logging component that I will access in other assemblies. So it
was brought up to me that I should pass an instance around to these
components instead of just making the logging class static. If I make it
static I wouldn''t need to
pass an instance around. What is your take on this?
一个重要的决定,这取决于你的需求。你的班级需要
来保留州吗?这有多复杂?如何记忆饥渴?
-
Tom Spink
爱丁堡大学
Hi,
An important decision, and it depends on your needs. Does your class need
to retain state? How complicated is it? How memory-hungry is it?
--
Tom Spink
University of Edinburgh
6月27日上午10:30,JJ< J ... @ discussion.microsoft.comwrote:
On Jun 27, 10:30 am, JJ <J...@discussions.microsoft.comwrote:
我有一个日志组件,我将在其他程序集中访问。所以我告诉我,我应该将一个实例传递给这些组件
而不仅仅是使日志记录类保持静态。如果我让它静止我就不需要
传递一个实例。你对此有什么看法?
I have a logging component that I will access in other assemblies. So it was
brought up to me that I should pass an instance around to these components
instead of just making the logging class static. If I make it static I
wouldn''t need to
pass an instance around. What is your take on this?
您是否看过Microsoft Enterprise ApplicationBlocks?有一个
日志记录块可以满足您的需求。你可能想要使用它来代替它,或者在它之后模拟你的组件(源代码是
提供)。
http://msdn2.microsoft.com/en-us/library/aa480464。 aspx
这篇关于记录类 - 实例或静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!