Common.Logging.Elmah

這是前些日子寫的小元件,用來將Common.Logging與Elmah整合在一起,Common.Logging是記錄Log的介接元件,本身只有很陽春的ConsoleOut與Trace的記錄功能,但它強在可以與.Net中最常見的三套Logging元件整合,整合的元件有log4net、Enterprise Library Logging、 NLog,讓你在寫中間層元件時,如:DAO、Controls等等,只需要對Common.Logging提供的介面操作,等到使用中間層元件的專案在決定用三套的其中一套來記錄Log,增加元件的使用彈性,但很可惜的不支援Elmah,雖然可以讓Common.Logging+Nlog(或其他二套)與Elmah寫在同一個DB中,讓Elmah也可以呈現Common.Logging所寫入的Log,但是專案就會多參考一個dll,感覺很討厭,所以就花了一點時間寫了一個與Elmah介接元作。

 

安裝

NuGet網址

使用NuGet Package Manager中搜尋Common.Logging.Elmah下載安裝

使用Package Manager Console中輸入

PM> Install-Package Common.Logging.Elmah

 

設定

使用NuGet下載時會自動在web.config或app.config中增加設定

<configuration>
  <configSections>
    <sectionGroup name="common">
      <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
    </sectionGroup>
  </configSections>
  <common>
    <logging>
      <factoryAdapter type="Common.Logging.Elmah.ElmahLoggerFactoryAdapter, Common.Logging.Elmah">
        <arg key="MinLevel" value="all"/>
      </factoryAdapter>
    </logging>
  </common>
</configuration>

其中MinLevel參數為最小要記錄的層級,使用Common.Logging.LogLevel的enum值(不分大小寫)。

namespace Common.Logging
{
    public enum LogLevel
    {
        All = 0,
        Trace = 1,
        Debug = 2,
        Info = 3,
        Warn = 4,
        Error = 5,
        Fatal = 6,
        Off = 7,
    }
}

 

下載原始碼


2011/10/6 02:28 | 閱讀數 : 22844 我要推薦 | 6 Comments | 文章分類 : .Net 訂閱


回覆

# re: Common.Logging.Elmah, Posted by ilia on 2012/3/14 下午 06:26  回覆

Write in english, please))

# re: Common.Logging.Elmah, Posted by Nanoko on 2012/4/19 上午 03:19  回覆

Actually, the v1.1 has a major miscoding. You'll need to set this in Web.config in order to log "Info" level and above :

 

<common>
    <logging>
      <factoryAdapter type="Common.Logging.Elmah.ElmahLoggerFactoryAdapter, Common.Logging.Elmah">
        <arg key="MixLevel" value="Debug" />
      </factoryAdapter>
    </logging>
  </common>
 
Plus the logger always responds "true" on "Is<level>Enabled" methods, not regarding this setting.

# re: Common.Logging.Elmah, Posted by 黃偉榮 on 2012/6/5 下午 01:52  回覆

抱歉!!拖到現在才處理,問題修改好了

Sorry, bug is  fix. 

# re: Common.Logging.Elmah, Posted by Hoisel on 2012/10/10 上午 08:44  回覆

Hello,

Congratulations! Good work! Please, host the source in a repository like github!

Thanks,

Hoisel

# re: Common.Logging.Elmah, Posted by Shawn on 2013/10/23 上午 09:36  回覆

Stephen/Wade, (The author configured for the nuget package is listed as "Wade".)

I need to add some functionality to the great library you've provided (we've adopted it for all our applications :-), so I created a repository for the source you provided on Github:

https://github.com/shawn-bellevuecollege/common-logging-elmah

I'd be more than happy to manage the repository there and welcome you to join me as a repo owner if you'd like. Or even give you sole ownership, if you'd rather.

I also couldn't find a license specified for this library. Did you have one in mind? If not, do you mind if I put it under the LGPL?

Thanks again for all your work, and for making this available to us :-)

- Shawn South

Senior Software Engineer, Bellevue College, WA, USA

# re: Common.Logging.Elmah, Posted by Wade on 2013/10/24 上午 10:35  回覆

to Shawn :
sure, I have already tranfer an ownership to you.

發表回覆

標題: *
姓名: *
Email: (將不會被顯示)
Url:
回覆: *
登入後使用進階評論
Please add 1 and 5 and type the answer here:

標籤

more tags...

每月文章

文章分類

開發資源

最新回覆