How to output messages of various levels in log4net to configuration files of different log files

Source: Internet
Author: User
Tags log4net
Body: This is a configuration file that uses log4net 1.2.9.0 to output messages of different levels to different log files. log4net. config adds references to the project and adds a sentence to assemblyinfo. CS: [Assembly: log4net. config. xmlconfigurator (configfile = "log4net. config", watch = true)] Add in Application_OnStart-WebForm or in main function-winform Log4net. config. xmlconfigurator. Configure (new system. Io. fileinfo ("log4net. config ")); <? XML version = "1.0" encoding = "UTF-8"?>
<Log4net>
<! --
All/fatal> error> warn> info> debug/off <logger name = "penavicoxmlogger">
<Level value = "all"/>
<Appender-ref = "logfileappender"/>
</Logger>
<Appender name = "logfileappender" type = "log4net. appender. fileappender">
<Param name = "file" value = "penavicoxm.log.txt"/>
<Param name = "rollingstyle" value = "date"/>
<Param name = "datepattern" value = "mm-dd hh: mm"/>
<Param name = "appendtofile" value = "true"/>
<Layout type = "log4net. layout. patternlayout">
<Param name = "conversionpattern" value = "% d [% T] %-5 p % C-% m % N"/>
</Layout>
</Appender>
<Root>
<Level value = "all"/>
<Appender-ref = "debuglog"/>
</Root> -->
<Root>
<Level value = "all"/>
<Appender-ref = "debuglog"/>
<Appender-ref = "infolog"/>
<Appender-ref = "warnlog"/>
<Appender-ref = "errorlog"/>
<Appender-ref = "fatallog"/>
</Root>
<! --
<Root>
<Level value = "debug"/>
<Appender-ref = "debuglog"/>
</Root>
<Root>
<Level value = "Fatal"/>
<Appender-ref = "fatallog"/>
</Root>
<Root>
<Level value = "Warn"/>
<Appender-ref = "warnlog"/>
</Root>
<Root>
<Level value = "error"/>
<Appender-ref = "errorlog"/>
</Root> -->
<Appender name = "infolog" type = "log4net. appender. rollingfileappender">
<File value = "log \"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "YYYY \ mm \ DD-In \ fo'.txt '"/>
<Staticlogfilename value = "false"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% d [% T] %-5 p % C % L-% m % N"/>
</Layout>
<Filter type = "log4net. Filter. levelrangefilter">
<Param name = "levelmin" value = "info"/>
<Param name = "levelmax" value = "info"/>
</Filter> </appender>
<Appender name = "debuglog" type = "log4net. appender. rollingfileappender">
<File value = "log \"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "YYYY \ mm \ DD-Debu \ g'.txt '"/>
<Staticlogfilename value = "false"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% d [% T] %-5 p % C % L-% m % N"/>
</Layout>
<Filter type = "log4net. Filter. levelrangefilter">
<Param name = "levelmin" value = "debug"/>
<Param name = "levelmax" value = "debug"/>
</Filter>
</Appender>
<Appender name = "fatallog" type = "log4net. appender. rollingfileappender">
<File value = "log \"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "YYYY \ mm \ DD-\ fa \ tal'.txt '"/>
<Staticlogfilename value = "false"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% d [% T] %-5 p % C % L-% m % N"/>
</Layout>
<Filter type = "log4net. Filter. levelrangefilter">
<Param name = "levelmin" value = "Fatal"/>
<Param name = "levelmax" value = "Fatal"/>
</Filter>
</Appender>
<Appender name = "warnlog" type = "log4net. appender. rollingfileappender">
<File value = "log \"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "YYYY \ mm \ dd-warn'.txt '"/>
<Staticlogfilename value = "false"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% d [% T] %-5 p % C % L-% m % N"/>
</Layout>
<Filter type = "log4net. Filter. levelrangefilter">
<Param name = "levelmin" value = "Warn"/>
<Param name = "levelmax" value = "Warn"/>
</Filter>
</Appender>
<Appender name = "errorlog" type = "log4net. appender. rollingfileappender">
<File value = "log \"/>
<Appendtofile value = "true"/>
<Rollingstyle value = "date"/>
<Datepattern value = "YYYY \ mm \ dd-error'.txt '"/>
<Staticlogfilename value = "false"/>
<Layout type = "log4net. layout. patternlayout">
<Conversionpattern value = "% d [% T] %-5 p % C % L-% m % N"/>
</Layout>
<Filter type = "log4net. Filter. levelrangefilter">
<Param name = "levelmin" value = "error"/>
<Param name = "levelmax" value = "error"/>
</Filter>
</Appender>
</Log4net> log4net is just used, and configuration may be cumbersome. It mainly uses filter. Do you have a simple configuration? Category: C #. net Release date:

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.