System.ArgumentOutOfRangeException log4net

System.ArgumentOutOfRangeException log4net

我随机得到这个异常。从下面的堆栈跟踪中我可以了解到它源自 log4net 功能。

LogExceptionValue  - 
System.ArgumentOutOfRangeException: capacity was less than the current size.
Parameter name: value
at System.Collections.ArrayList.set_Capacity(Int32 value)
at System.Collections.ArrayList.Add(Object value)
at log4net.Util.LogReceivedEventHandler.Invoke(Object source, LogReceivedEventArgs e)
at log4net.Util.LogLog.OnLogReceived(Type source, String prefix, String   message, Exception exception)
at log4net.Config.XmlConfigurator.InternalConfigure(ILoggerRepository  repository)
at log4net.Config.XmlConfigurator.Configure(ILoggerRepository repository)
at log4net.Config.XmlConfigurator.Configure()
at Loggers.LoggerBase.LogMessage(LogInformation logInformation)
at LookupByReasonCode(String reasonCode)

Log4Net 代码

 /// <summary>
    ///  Logs message based on logger.
    /// </summary>
    /// <param name="logInformation">Log Information </param>
    protected void LogMessage(LogInformation logInformation)
    {
        this.log = LogManager.GetLogger(logInformation.Logger);
        log4net.Config.XmlConfigurator.Configure();

        if (!string.IsNullOrEmpty(logInformation.Request))
        {
            ThreadContext.Properties["request"] = logInformation.Request;
        }

        if (!string.IsNullOrEmpty(logInformation.Response))
        {
            ThreadContext.Properties["response"] = logInformation.Response;
        }

        if (!string.IsNullOrEmpty(logInformation.ResponseCode))
        {
            ThreadContext.Properties["responsecode"] = logInformation.ResponseCode;
        }

        if (!string.IsNullOrEmpty(logInformation.Keys))
        {
            ThreadContext.Properties["keys"] = logInformation.Keys;
        }

        //// Logs exception
        this.Log(logInformation.Message, logInformation.LogLevel, logInformation.Exception);
    }

如有任何帮助,我们将不胜感激。

如果您间歇性地得到这个,很可能是因为您在每个日志调用和两个线程上加载 log4net 配置正在尝试同时加载它。

XmlConfigurator.Configure(); 移动到您的启动程序,并且只调用它一次。