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: