Use of log4net

Source: Internet
Author: User
Tags log4net

1. NuGet Download log4net

2. Add configuration information in app. Config

< Sectionname= "Log4net"type= "log4net." Config.log4netconfigurationsectionhandler, log4net " />  <log4net>    <!--OFF, FATAL, ERROR, WARN, INFO, DEBUG, all -    <!--Set Root Logger level-to-ERROR and its appenders -    <Root>      < Levelvalue= "All" />      <Appender-refref= "Sysappender" />    </Root>    <!--Print only messages of level DEBUG or above in the packages -    <Loggername= "Testlogger">      < Levelvalue= "All" />    </Logger>    <Appendername= "Sysappender"type= "log4net." Appender.rollingfileappender,log4net ">      <!--Log Directory -      <paramname= "File"value= "log/" />      <paramname= "Appendtofile"value= "true" />      <paramname= "Rollingstyle"value= "Date" />      <!--Log Naming -      <paramname= "Datepattern"value= "&quot; Logs_&quot;yyyymmdd&quot;. txt&quot; " />      <paramname= "Staticlogfilename"value= "false" />      <Layouttype= "log4net." Layout.patternlayout,log4net ">        <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" />      </Layout>    </Appender>    <Appendername= "ConsoleApp"type= "log4net." Appender.consoleappender,log4net ">      <Layouttype= "log4net." Layout.patternlayout,log4net ">        <paramname= "Conversionpattern"value= "%d [%t]%-5p%c-%m%n" />      </Layout>    </Appender>  </log4net>

3. Add the following code in AssemblyInfo.cs or above the log class namespace

// log4net reading the configuration from the configuration file " Config " true)]

(Specify configuration file method)

// Add log4net information " Log.config " true)]

4. Using log4net

Private StaticILog log = Logmanager.getlogger ("Testlogger"); Static voidMain (string[] args) {log. Debug ("Debug Log"); Log. Info ("Info Log"); Log. Warn ("warn log"); Log. Error ("error Log"); }

Use of log4net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.