标签:root div 读取 ror file .config col -- OLE
1、NuGet上下载log4net
2、App.config中添加配置信息
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> <log4net> <!-- OFF, FATAL, ERROR, WARN, INFO, DEBUG, ALL --> <!-- Set root logger level to ERROR and its appenders --> <root> <level value="ALL" /> <appender-ref ref="SysAppender" /> </root> <!-- Print only messages of level DEBUG or above in the packages --> <logger name="TestLogger"> <level value="ALL" /> </logger> <appender name="SysAppender" type="log4net.Appender.RollingFileAppender,log4net"> <!-- 日志目录 --> <param name="File" value="Log/" /> <param name="AppendToFile" value="true" /> <param name="RollingStyle" value="Date" /> <!-- 日志命名 --> <param name="DatePattern" value=""Logs_"yyyyMMdd".txt"" /> <param name="StaticLogFileName" value="false" /> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" /> </layout> </appender> <appender name="consoleApp" type="log4net.Appender.ConsoleAppender,log4net"> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" /> </layout> </appender> </log4net>
3.在AssemblyInfo.cs中 或 日志类namespace上方添加如下代码
//log4net从配置文件中读取配置 [assembly: log4net.Config.XmlConfigurator(ConfigFileExtension = "config", Watch = true)]
(指定配置文件方法)
//添加log4net信息 [assembly: log4net.Config.DOMConfigurator(ConfigFile = "Log.config", Watch = true)]
4.使用log4net
private static ILog log = LogManager.GetLogger("TestLogger"); static void Main(string[] args) { log.Debug("Debug日志"); log.Info("Info日志"); log.Warn("Warn日志"); log.Error("Error日志"); }
标签:root div 读取 ror file .config col -- OLE
原文地址:https://www.cnblogs.com/MrZheng/p/8966725.html