标签:end private tco 引用 stat extension 技术 ndt gty
右键引用,选择 管理NuGet程序包,选择浏览,输入log4net,然后点击下载
<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> </configSections> <log4net> <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="logs\\" /> <param name="AppendToFile" value="true" /> <param name="MaxSizeRollBackups" value="100" /> <param name="MaximumFileSize" value="2MB" /> <!--日志文件名设置--> <param name="RollingStyle" value="Date" /> <param name="StaticLogFileName" value="false" /> <param name="DatePattern" value=""Logs_"yyyyMMdd".txt"" /> <!--信息日志布局--> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="[%d] [%t] [%-5p] [%c] : %m%n" /> </layout> </appender> <root> <level value="all" /> <appender-ref ref="RollingLogFileAppender" /> </root> </log4net> </configuration>
//log4net从配置文件中读取配置 [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)]
//当前文件名 private log4net.ILog Log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); Log.Error("哈哈"); Log.Info("哈哈");
文件:
打印效果:
[2019-01-31 09:46:08,092] [1] [INFO ] [Import.Program] : program start!
<param name="ConversionPattern" value="[%d] [%t] [%-5p] [%c] : %m%n" /> [日期时间] [线程] [日志级别] [日志出处]:日志
标签:end private tco 引用 stat extension 技术 ndt gty
原文地址:https://www.cnblogs.com/yaosj/p/10342302.html