本人很喜欢VB.NET使用Log4Net,在工作中也很喜欢总结关于VB.NET使用Log4Net的经验教训,下面就这个问题来详细说说吧。
VB.NET使用Log4Net
- <configSections>
- <sectionnamesectionname="log4net"type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
- configSections>
- <log4net>
- <root>
- <levelvaluelevelvalue="ALL"/>
- <appender-refrefappender-refref="rollingFile"/>
- root>
- <appendernameappendername="rollingFile"type="log4net.Appender.RollingFileAppender,log4net">
- <paramnameparamname="File"value="log.txt"/>
- <paramnameparamname="AppendToFile"value="True"/>
- <paramnameparamname="RollingStyle"value="Date"/>
- <paramnameparamname="DatePattern"value="yyyy.MM.dd"/>
- <paramnameparamname="StaticLogFileName"value="true"/>
- <layouttypelayouttype="log4net.Layout.PatternLayout,log4net">
- <paramnameparamname="ConversionPattern"value="%d[%t]%-5p%c-%m%n"/>
- <paramnameparamname="Header"value="
----------------------header-------------------------- "/>- <paramnameparamname="Footer"value="
----------------------footer-------------------------- "/>- layout>
- appender>
- <appendernameappendername="consoleApp"type="log4net.Appender.ConsoleAppender,log4net">
- <layouttypelayouttype="log4net.Layout.PatternLayout,log4net">
- <paramnameparamname="ConversionPattern"value="%d[%t]%-5p%c-%m%n"/>
- layout>
- appender>
- <loggernameloggername="Log4NetTest.LogTest">
- <levelvaluelevelvalue="DEBUG"/>
- <appender-refrefappender-refref="rollingFile"/>
- <appender-refrefappender-refref="SystemEvent"/>
- logger>
- log4net>
level定义记录的日志级别,有以下几种
◆None
◆Fatal
◆ERROR
◆WARN
◆DEBUG
◆INFO
◆ALL
新建VB.NET项目,新建一Form添加VB.NET使用Log4Net声明