配置文件
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"> <param name="File" value="Logs\\" /> <param name="AppendToFile" value="true" /> <param name="MaxSizeRollBackups" value="-1" /> <param name="MaximumFileSize" value="10MB" /> <param name="RollingStyle" value="Composite" /> <param name="StaticLogFileName" value="true" /> <DatePattern value="yyyy-MM-dd".txt""/> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" /> <layout type="log4net.Layout.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" /> </layout> </appender> <root> <level value="ALL" /> <appender-ref ref="RollingLogFileAppender" /> </root>
在程序集也配置了这玩意
[assembly: log4net.Config.XmlConfigurator("App.config", Watch = true)]
还自定义了一个错误,List<string> list=null; string a=list[0];
k可是 IsErrorEnabled 一直是false
是日志写不进去吗?试一下在Main()的第一行,或Global的Application_Start里加一句log4net.Config.DOMConfigurator.Configure();
并删除[assembly: log4net.Config.XmlConfigurator("App.config", Watch = true)]
我试试哈
我用了一个loghelper 类
public class LogHelper { public static readonly ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); /// <summary> /// 输出日志到Log4Net /// </summary> /// <param name="t"></param> /// <param name="ex"></param> #region static void WriteLog(Exception ex) public static void WriteLog(Exception ex) { if (log.IsErrorEnabled) { log.Error("Error", ex); } } #endregion /// <summary> /// 输出日志到Log4Net /// </summary> /// <param name="t"></param> /// <param name="msg"></param> #region static void WriteLog(string msg) public static void WriteLog(string msg) { if (log.IsErrorEnabled) { log.Error(msg); } } #endregion }