使用日志框架的要点是什么

使用日志框架的要点是什么

本文介绍了使用日志框架的要点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我可能会丢失其日志框架为你的应用点。在所有的小应用程序我一直写了一个小的记录类,只是通过登录消息中有一个方法,它被写入到文件中。

I think I might be missing the point of having a logging framework for your application. In all the small apps I've always written a small "Logging" class and just pass log messages to a method in it which is written to a file.

什么的第三方日志框架像log4net的目的是什么?难道是线程安全与记录写操作还是我失去了一些东西?

What is the purpose of a 3rd party logging framework like log4net? Is it thread safety with logging write operations or am I missing something?

推荐答案

这是一个非常好的问题。

That's an excellent question.

第一个原因是为什么不呢?如果您正在使用日志框架,那么你将收获使用的东西已经打包的可维护性的好处。

The first reason is "why not?" If you are using a logging framework, then you'll reap the maintainability benefits of using something already packaged.

第二个原因是,日志记录是很微妙的。不同的线程,会话类和对象实例都可能进入采伐发挥,而你不希望要搞清楚这个问题出在飞行。

The second reason is that logging is subtle. Different threads, sessions, classes and object instances may all come into play in logging, and you don't want to have to figure this problem out on the fly.

第三个原因是,你可能会发现你的code性能瓶颈。搞清楚你的​​code是缓慢的,因为你写一个文件没有缓冲或硬盘驱动器已经运行的磁盘空间,因为记录器不展期和COM preSS旧的文件可以在疼痛颈部。

The third reason is that you may find a performance bottleneck in your code. Figuring out that your code is slow because you're writing to a file without buffering or your hard drive has run out of disk space because the logger doesn't rollover and compress old files can be a pain in the neck.

第四个原因是,你可能要附加到系统日志,或写入到数据库,或一个插座,或以不同的文件。框架有此功能内置的。

The fourth reason is that you may want to append to syslog, or write to a database, or to a socket, or to different files. Frameworks have this functionality built in.

不过说真的,第一个答案是最好的;有很少的好处写你自己的,和一大堆缺点。

But really, the first answer is the best one; there's very little benefit to writing your own, and a whole bunch of drawbacks.

这篇关于使用日志框架的要点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:26