log4net info 方法 根据不同业务创建不同的文件名
<configuration> <!-- ... 其他配置 ... --> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <appender name="RollingFileAppenderA" type="log4net.Appender.RollingFileAppender"> <file value="logs/BusinessA.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> </appender> <appender name="RollingFileAppenderB" type="log4net.Appender.RollingFileAppender"> <file value="logs/BusinessB.log" /> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="5" /> <maximumFileSize value="10MB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" /> </layout> </appender> <logger name="BusinessA"> <additivity value="false" /> <level value="INFO" /> <appender-ref ref="RollingFileAppenderA" /> </logger> <logger name="BusinessB"> <additivity value="false" /> <level value="INFO" /> <appender-ref ref="RollingFileAppenderB" /> </logger> <root> <level value="INFO" /> <!-- 如果你还想为根logger配置appender,可以在这里添加 --> </root> </log4net> <!-- ... 其他配置 ... --> </configuration>
使用:
// 获取BusinessA的logger实例 ILog logA = LogManager.GetLogger("BusinessA"); logA.Info("This is a log message for BusinessA."); // 获取BusinessB的logger实例 ILog logB = LogManager.GetLogger("BusinessB"); logB.Info("This is a log message for BusinessB.");
--
标签:log4net,info,BusinessA,BusinessB,不同,文件名 From: https://www.cnblogs.com/runliuv/p/18228454