Log4net(一)設定檔

來源:互聯網
上載者:User
正在學習,不對的請指教
1、下載:log4net:
sourceforge有原始碼下載:http://sourceforge.net/project/showfiles.php?group_id=31983&package_id=24080&release_id=171808
2、參考sdk和manua在原始碼包的doc目錄下
3、log4net的例子:http://logging.apache.org/log4net/release/config-examples.html
資料:http://blogs.acceleration.net/ryan/articles/379.aspx
下面是cuyahoga的設定檔:<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="CuyahogaSettings" type="Cuyahoga.Core.Util.CuyahogaSectionHandler, Cuyahoga.Core" />
    <section name="UrlMappings" type="Cuyahoga.Web.HttpModules.UrlMappingsSectionHandler, Cuyahoga.Web" />
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
  </configSections>
  <log4net debug="false">
    
    <!-- 總:appender,定義輸出介質 Appenders may only be defined as child elements of the <log4net> element.
     Each appender must be uniquely named. The implementing type for the appender must be specified.  -->
     <!-- 說明name 
     Required attribute. Value must be a string name for this appender. The name must be unique among all the appenders defined in this configuration file.
      This name is used by the <appender-ref> element of a Logger to reference an appender. 
       -->
     <!-- 說明type: Required attribute. Value must be the type name for this appender. If the appender is not defined in the log4net assembly this type name must be fully assembly qualified. -->
    <!-- RollingFileAppender: 輸出到檔案-->
    <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net"><!-- 設定好像有問題,一些設定衝突-->
    <!-- 定義RollingFileAppender的屬性 -->
      <param name="File" value="log/log.txt" /><!-- Gets or sets the path to the file that logging will be written to. -->
      <param name="AppendToFile" value="true" /><!--Gets or sets a flag that indicates weather the file should be appended to or overwritten -->
      <param name="StaticLogFileName" value="true" /><!-- true if always should be logged to the same file --><!-- 使的下面三行的設定無效-->
      
      <param name="RollingStyle" value="Date" /><!-- Gets or sets the rolling style ,Date是RollingMode枚舉值Roll files based only on the date  -->
      <param name="DatePattern" value="yyyy.MM.dd" /><!-- Gets or sets the datepattern to be used for generating file names when rolling over on date.  -->
      
        <param name="CountDirection" value="1" /><!-- CountDirection > 0  does the opposite ,從1開始增加是無窮的-->     
      
    <!--檔案名稱的格式為 :(or file.log.curSizeRollBackup or even file.log.yyyy-mm-dd.curSizeRollBackup).  -->
      <!--  Layout:輸出日誌的格式化器
        用於向使用者顯示最後經過格式化的輸出資訊。輸出資訊可以以多種格式顯示,主要依賴於我們採用的Layout組件類型。
        可以是線性或一個XML檔案。Layout組件和一個Appender組件一起工作。API協助手冊中有關於不同Layout組件的列表。
        一個Appender對象,只能對應一個Layout對象。要實現你自己的Layout類,你需要從log4net.Layout.LayoutSkeleton類繼承,它實現了ILayout介面。 
        Layout elements may only be defined as children of <appender> elements. -->
      <layout type="log4net.Layout.PatternLayout,log4net"> <!-- Defines the layout used by this appender -->
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />
      </layout>
    </appender>
    
    <root>
      <priority value="ERROR" /><!-- 文檔上只看到level 元素?-->
      <!--level: Optional element, maximum of one allowed. Defines the logging level for this 
            logger. This logger will only accept event that are at this level or above-->
      <appender-ref ref="rollingFile" />
    </root>
    
    <logger name="Cuyahoga.Core.Service.CoreRepository">
      <level value="ERROR" />
    </logger>
    
    <logger name="Cuyahoga.Web.HttpModules.UrlHandlerModule">
      <level value="INFO" />
    </logger>
</log4net>

</configuration>
<!-- root 在架構的體系裡,所有的日誌對象都是根日誌(root logger)的後代。 
因此如果一個日誌對象沒有在設定檔裡顯式定義,則架構使用根日誌中定義的屬性。在<root>標籤裡,可以定義level層級值和Appender的列表。
如果沒有定義LEVEL的值,則預設為DEBUG。可以通過<appender-ref>標籤定義日誌對象使用的Appender對象。<appender-ref>聲明了在其他地方定義的Appender對象的一個引用。在一個logger對象中的設定會覆蓋根日誌的設定。
而對Appender屬性來說,子日誌對象則會繼承父日誌對象的Appender列表。這種預設的行為方式也可以通過顯式地設定<logger>;標籤的additivity屬性為false而改變。--> 
<!-- 格式名含義
%c輸出日誌資訊所屬的類的全名
%d輸出日誌時間點的日期或時間,預設格式為ISO8601,也可以在其後指定格式,比如:%d{yyy-MM-ddHH:mm:ss},輸出類似:2002-10-18-22:10:28
%f輸出日誌資訊所屬的類的類名
%l輸出日誌事件的發生位置,即輸出日誌資訊的語句處於它所在的類的第幾行
%m輸出代碼中指定的資訊,如log(message)中的message
%n輸出一個斷行符號分行符號,Windows平台為“\r\n”,Unix平台為“\n”
%p輸出優先順序,即DEBUG,INFO,WARN,ERROR,FATAL。如果是調用debug()輸出的,則為DEBUG,依此類推
%r輸出自應用啟動到輸出該日誌資訊所耗費的毫秒數
%t輸出產生該日誌事件的線程名
 -->    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.