log4net vs. Nlog [closed]
在Stack over flow 上看到的
http://stackoverflow.com/questions/710863/log4net-vs-nlog
I was recently tasked to "prototype up some loggin'" for an upcoming project. I didn't have any logging framework experience. I researched, ran through tutorials, made toy apps, etc. on Log4Net, NLog, and Enterprise Library for a few days. Came back 3-4 weeks later and put them together into a cohesive demo. Hopefully some of this is useful to you.
最近我为一个新项目选择一个"日志框架(framework)"。由于我之前没有任何的日志框架经验,于是我搜索,阅读入门手册,运行demo等待,经过3,4周的黑暗摸索,本屌终于对log4net,Nlog,Enterprise Libary(企业库)有了一个大概的了解:
My recommendation for our project is this:
本屌建议:
- Use a logging facade to avoid direct dependencies. 使用日志门门面模式避免直接操作。 (啥是门面模式请看文章结尾),大意是说不要每个页面都
Logger logger = LogManager.GetCurrentClassLogger(); logger.Log("看你妹");
而是建立一个静态类 直接调用,比如
ProjectNameLoggerManger.Error("错误消息:"+e.Message);
- If we end up using Enterprise Library for other facilities, then use it for Logging, too.如果我们的终端(程序)已经用企业库,那就用企业库日志吧
- If we end up using something with a dependency on Log4Net, use Log4Net.如果我们的程序已经用了第三方日志 log4Net 就用吧
- If none of the above, use NLog. Which I'd prefer.如果你是一个全新项目,或者压根还未用到日志,或者在写着自己的猥琐日志方法,用NLOG吧,我墙裂推荐。
That's based on these findings (opinions!):
以下是根据基于老夫多年(3-4周)的发现(仅供参考)
- All 3 frameworks are capable and can do some sophisticated things. We want a quality solution, but frankly don't need ultra high performance or 60 types of event sinks.
- 3个框架都很好很强大,可以处理复杂的日志情况。我的这个项目,需要一个高品质的解决方案,但是不需要对性能有极高要求和超复杂的事件类型(60种事件槽?求高手解答这个概念)
- All 3 have very similar basic concepts.
- 3个框架都拥有相似的基本概念。(.....此处省略2万字)
- Each has its own cool tricks, like really advanced routing, or dynamic log filenames, file truncating, etc.
- 它们都有自己的超酷玩意儿,比如高级路由,动态日志文件,文件大小控制,文件截断等待...
- All 3 are pretty well documented in their own way.
- 她们都有自己的完整文档(尼玛,我找了半天的NLOG 数据库配置)
- For a complete newb like me, they were all a little awkward initially. No drastic differences here for the basics. I got over it.
- 对我这样一个非常十分高端牛逼(newb)的程序员,这3个框架的初始化看起来有些蛋疼,但基本上疼的不是很激烈,我克服一下就过去了。
- When revisiting things a few weeks later, NLog was clearly the easiest to resume. I needed very little brush up on it. With Log4Net, I had to revisit a few online examples to get going. With EntLib, I gave up and did the tutorials all over again from scratch - I was totally lost.
- 过了几天,我重新复习一下3个日志款框架,NLOG我瞄一眼就知道理解了,LOG4NET我稍微多花了一些时间就理解了,至于企业库,我勒了个去,劳资又跑到官网去看《基本入门手册》了---我完全被它打败了。
- I couldn't figure out how to get EntLib to do some things like log to the database. It might be easy, but it was beyond my time limit.
- 我完全不知道怎么配置/使用企业库的数据库日志(怎么样把日志写到数据库中)。也许它很简单,但是像我这样非常高端牛逼(newb)的职业程序员就捉急的找不到.....
- Log4Net and NLog have a small in-code footprint. EntLib is spammy, but I'd use a facade over it anyway.
- 这句话的意思貌似是从某个方面(代码嵌入??)log4Nte he Nlog比企业库好那么一点点。
- I accidentally mis-configured EntLib and it told me at run time. Log4Net didn't. I didn't have an accidental mis-config with NLog.
- 有一次我意外的忘记配置企业库,这货居然等到程序跑起来了才告诉我说没有配置好文件,Nlog就不存在介个问题。最牛b的是nlog,我从没机会配置错。
- EntLib comes with a nice looking app.config editor, which you 100% need. NLog has a config file schema so you get "intellisense". Log4Net comes with nada.
- 企业库会给你一个漂亮的appconfig编辑器,你会很喜欢它,Nlog有“智能感应”哦,Log4net 木有这些东东
nada /ˈnɑːdə/ 1. Nnothing 无物[美国英语][非正式]
So obviously I like NLog so far. Not enough to use it in spite of having another solution available, though.
所以明显的,我很喜欢NLOG。
门面模式传送门:http://www.cnblogs.com/cj723/archive/2007/03/28/689955.html