<?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <!--定义输出到文件中--> <appender name="RollingLogFileAppender_DateFormat" type="log4net.Appender.RollingFileAppender"> <file value="E:/weixinLogs/zwy.txt"/> <appendToFile value="true"/> <rollingStyle value="Date"/> <datePattern value="yyyyMMdd"/> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date (%file:%line) %-5level %logger [%property{NDC}] - %message%newline"/> </layout> </appender> <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date (%file:%line) %-5level %logger [%property{NDC}] - %message%newline"/> </layout> </appender> <root> <!--control log level: ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF--> <!--假如没有定义LEVEL的值,则缺省为DEBUG--> <level value="debug"/> <!--文件形式记录日志--> <appender-ref ref="RollingLogFileAppender_DateFormat"/> <!--控制台控制显示日志-System.Diagnostics.Debug.Write("");//控制台显示 <appender-ref ref="ConsoleAppender"/>--> <!--Windows事件日志 <appender-ref ref="EventLogAppender" />--> <!-- 假如不启用相应的日志记录,可以通过这种方式注释掉 <appender-ref ref="AdoNetAppender_Access" />--> </root> </log4net> <!--Log4net End--> </configuration>
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
解决方案