设计问题...... [英] Design question...

查看:105
本文介绍了设计问题......的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个可重复使用的日志类。

我的目标是让它尽可能快速和健壮,同时保持内存使用率最低。所有成员都是静态的。


出于某种原因,我坚持以下设计问题。

显然你需要一个流来写日志文件。

每次需要编写日志时都应创建此流,或者如果流是作为日志记录类的成员变量的
,则只需要

每个应用程序生命周期开启和关闭一次。


有人可以建议正确的方式去这里以及为什么?

这似乎是一个简单的问题但是由于某种原因,我不能决定

这是正确的方法。它甚至重要吗?

I am writing a reusable class for logging.
My goal is to make it as fast and as robust as possible, while keeping
memory usage to the lowest. All members are static.

For some reason I''m stuck on the following design question.
Obviously you need a stream to write the log file.
Should this stream be created every time the log needs to be written, or
should the stream be a member variable of the logging class and only be
opened and closed once per application lifetime.

Can someone suggest the right way to go here and why?
This seems like a simple question but for some reason I can''t decide
which is the right way to do this. Does it even matter?

推荐答案

" Nick Z." < PA ***** @ gmail.com>在消息中写道

新闻:OO ************** @ fe10.lga ...
"Nick Z." <pa*****@gmail.com> wrote in message
news:OO**************@fe10.lga...
我正在写一个可重复使用的课程记录。
我的目标是让它尽可能快速和健壮,同时保持内存使用率最低。所有成员都是静态的。

由于某种原因,我坚持以下设计问题。
显然你需要一个流来写日志文件。
这个流应该是每次需要编写日志时创建,或者流应该是日志类的成员变量,并且每个应用程序生命周期只打开和关闭一次。

可以有人建议去这里的正确方法,为什么?
这似乎是一个简单的问题,但由于某种原因,我无法决定哪种方法是正确的。它是否重要?
I am writing a reusable class for logging.
My goal is to make it as fast and as robust as possible, while keeping
memory usage to the lowest. All members are static.

For some reason I''m stuck on the following design question.
Obviously you need a stream to write the log file.
Should this stream be created every time the log needs to be written, or
should the stream be a member variable of the logging class and only be
opened and closed once per application lifetime.

Can someone suggest the right way to go here and why?
This seems like a simple question but for some reason I can''t decide which
is the right way to do this. Does it even matter?




对于日志,我每次打开和关闭流。如果有人碰巧

preofturely你需要能够看到日志。


Michael



For logs I open and close the stream each time. If someone happens to
terminate the app premeturely you need to be able to see the log.

Michael

Michael C写道:
Michael C wrote:
" Nick Z." < PA ***** @ gmail.com>在消息中写道
新闻:OO ************** @ fe10.lga ...
"Nick Z." <pa*****@gmail.com> wrote in message
news:OO**************@fe10.lga...
我正在写一个可重复使用的课程记录。
我的目标是让它尽可能快速和健壮,同时保持内存使用率最低。所有成员都是静态的。

由于某种原因,我坚持以下设计问题。
显然你需要一个流来写日志文件。
这个流应该是每次需要编写日志时创建,或者流应该是日志类的成员变量,并且每个应用程序生命周期只打开和关闭一次。

可以有人建议去这里的正确方法,为什么?
这似乎是一个简单的问题,但由于某种原因,我无法决定哪种方法是正确的。它甚至重要吗?
I am writing a reusable class for logging.
My goal is to make it as fast and as robust as possible, while keeping
memory usage to the lowest. All members are static.

For some reason I''m stuck on the following design question.
Obviously you need a stream to write the log file.
Should this stream be created every time the log needs to be written, or
should the stream be a member variable of the logging class and only be
opened and closed once per application lifetime.

Can someone suggest the right way to go here and why?
This seems like a simple question but for some reason I can''t decide which
is the right way to do this. Does it even matter?



对于日志我每次打开和关闭流。如果有人恰好在应用程序之前终止应用程序,您需要能够查看日志。

Michael


For logs I open and close the stream each time. If someone happens to
terminate the app premeturely you need to be able to see the log.

Michael



$ b $嗯,真的。但是如果你在每次写入后强制流刷新怎么办。

我想我想知道每次创建流

的开销是多少。



Hmmm, true. But what if you force the stream to flush after each write.
I guess I want to know what the overhead is for creating the stream
every time.


嗨尼克,

我相信你有充分的理由编写自己的日志记录类,但是你看了一些

开箱即用的日志.Net为你提供了诸如
TextWriterTraceListener,你可以使用:


System.Diagnostics写入日志文件。跟踪或

System.Diagnostics.Debug类。


马克


" Nick Z."写道:
Hi Nick,
I am sure you have good reason to write your own logging class, but have
you looked at some of the out of the box logging .Net offers you such as a
TextWriterTraceListener, you can then write to log files using the:

System.Diagnostics.Trace or
System.Diagnostics.Debug classes.

Mark

"Nick Z." wrote:
我正在编写一个可重复使用的日志类。
我的目标是使其尽可能快速和健壮,同时保持内存使用量最低的。所有成员都是静态的。

由于某种原因,我坚持以下设计问题。
显然你需要一个流来写日志文件。
这个流应该是每次需要编写日志时创建,或者流应该是日志类的成员变量,并且每个应用程序生命周期只打开和关闭一次。

可以有人建议去这里的正确方法,为什么?
这似乎是一个简单的问题,但由于某种原因,我无法决定哪个是正确的方法。它甚至重要吗?
I am writing a reusable class for logging.
My goal is to make it as fast and as robust as possible, while keeping
memory usage to the lowest. All members are static.

For some reason I''m stuck on the following design question.
Obviously you need a stream to write the log file.
Should this stream be created every time the log needs to be written, or
should the stream be a member variable of the logging class and only be
opened and closed once per application lifetime.

Can someone suggest the right way to go here and why?
This seems like a simple question but for some reason I can''t decide
which is the right way to do this. Does it even matter?



这篇关于设计问题......的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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