Application of log4net in Windows service programs

Source: Internet
Author: User
Tags xml attribute log4net

1) The first step is also the most important step: Download a log4net. dll file, of course, you can also download the source file on the official website, and compile and generate such a file yourself

2) the configuration file is created. Create a log4net. xml file:

The configuration is as follows: the specific configuration depends on the situation. Only one framework is provided here:

<? XML version = "1.0" encoding = "UTF-8"?> <Configuration> <configsections> <section name = "log4net" type = "log4net. config. log4netconfigurationsectionhandler, log4net "/> </configsections> <log4net> <root> <level value =" error "/> </root> <logger name =" dataserverlog "> <level value =" error "> </level> <appender-ref =" dataserverappender "/> </logger> <appender name =" dataserverappender "type =" log4net. appender. fileappender "> <Param name =" file "type =" log4net. util. patternstring "value =" % log \ % Date {yyymmdd }. log "/> <Param name =" appendtofile "value =" true "/> <Param name =" rollingstyle "value =" date "/> <datepattern value =" yyyymmdd /" dataserver _ "yyyymmdd ". log ""/> <Param name = "maxsizerollbackups" value = "10"/> <Param name = "maximumfilesize" value = "5 MB"/> <Param name = "staticlogfilename "value =" false "/> <layout type =" log4net. layout. patternlayout "> <Param name =" conversionpattern "value =" record time: % date thread ID: [% thread] Log Level: %-5 level error class: % logger property: [% property {NDC}]-error Description: % message % newline "/> </layout> </appender> </log4net> </configuration>

3) add [Assembly: log4net. config. xmlconfigurator (configfile = "log4net. xml", watch = true) at the end of the assemblyinfo. CS file]

4) Replace the default value of copying data from the log4net. xml attribute to the output directory with: Always copy

Now, you can use log4net to generate a log file.

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.