首页 新闻 搜索 专区 学院

还是关于log4net的疑问

0
[已解决问题] 解决于 2015-05-14 09:51

配置文件

<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&quot;.txt&quot;"/>
<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

何必怀念As的主页 何必怀念As | 菜鸟二级 | 园豆:212
提问于:2015-05-14 08:42
< >
分享
最佳答案
0

是日志写不进去吗?试一下在Main()的第一行,或Global的Application_Start里加一句log4net.Config.DOMConfigurator.Configure();

并删除[assembly: log4net.Config.XmlConfigurator("App.config", Watch = true)]

奖励园豆:5
hexllo | 菜鸟二级 |园豆:397 | 2015-05-14 08:55

我试试哈

何必怀念As | 园豆:212 (菜鸟二级) | 2015-05-14 09:02

我用了一个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
    }

 

何必怀念As | 园豆:212 (菜鸟二级) | 2015-05-14 09:04
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册