新建Log4Net.config文件,内容为
<?xml version="1.0" encoding="utf-8" ?> <configuration> <!--log配置--> <log4net> <logger additivity="false" name="C#"> <level value="ALL" /> <appender-ref ref="RollingLogFileAppender" /> </logger> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <file type="log4net.Util.PatternString" value="%logs\%date{yyyMMdd}.txt"/> <appendToFile value="true" /> <rollingStyle value="Size" /> <maxSizeRollBackups value="10" /> <maximumFileSize value="100KB" /> <staticLogFileName value="true" /> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%d [%r] [%t] %-5p %c [%x] ----%m%n" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> </configuration>
在项目中的AssemblyInfo.cs文件中添加[assembly: log4net.Config.XmlConfigurator(ConfigFile = "Log4Net.config", Watch = true)]
新建个类
public class Logger
{
public static log4net.ILog logger = log4net.LogManager.GetLogger("RSGLServiceLog");
}
时间: 2024-10-11 05:18:25