preserveLogFileNameExtension
<log4net> <appender name="fileappender" type="log4net.Appender.RollingFileAppender"> <file value="logprogram.log" /> <encoding value="utf-8"/> <preserveLogFileNameExtension value="true" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value="_yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fffzzz} %-5p [%t]: %m%n" /> </layout> <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> </appender> <appender name="wcfAppender" type="log4net.Appender.RollingFileAppender"> <filter type="log4net.Filter.LevelMatchFilter"> <levelToMatch value="Error" /> </filter> <filter type="log4net.Filter.DenyAllFilter" /> <file value="logCommunicationException.log" /> <encoding value="utf-8"/> <preserveLogFileNameExtension value="true" /> <appendToFile value="true" /> <rollingStyle value="Date" /> <datePattern value="_yyyyMMdd" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date{yyyy-MM-dd HH:mm:ss.fffzzz} %logger - %message%newline" /> </layout> <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/> </appender> <root> <level value="Info" /> <appender-ref ref="fileappender" /> </root> <logger name="WcfException" additivity="false"> <level value="ALL" /> <appender-ref ref="wcfAppender" /> </logger> </log4net>
<preserveLogFileNameExtension value="true" />
这个属性的作用是,当前这一天的日志文件按照file来生成。在第二天的时候,把前一天的日志,加上datePattern。
watch
https://logging.apache.org/log4net/release/manual/configuration.html
在appsetting中加上
<appSettings> <add key="log4net.Config" value="log4net.config"/> <add key="log4net.Config.Watch" value="True"/> </appSettings>