在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