System.ArgumentOutOfRangeException log4net

时间:2016-07-22 12:41:00

标签: c# 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);
    }

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

如果您正在间歇地 ,那么很可能是因为您在每次单独的日志记录调用中加载log4net配置并且两个线程正在尝试并在同一时间加载它时间。

XmlConfigurator.Configure();移至启动程序,只调用一次。