2015-11-24 61 views
1

我在log4net的錯誤日誌中發現了以下錯誤:log4net的[1.2.14] - 一般失敗 - 參數缺少

log4net:ERROR [AdoNetAppender] ErrorCode: GenericFailure. Exception while writing to database 
System.IndexOutOfRangeException: An SqlParameter with ParameterName '@logId' is not contained by this SqlParameterCollection. 
    at System.Data.SqlClient.SqlParameterCollection.GetParameter(String parameterName) 
    at System.Data.Common.DbParameterCollection.System.Data.IDataParameterCollection.get_Item(String parameterName) 
    at log4net.Appender.AdoNetAppenderParameter.FormatValue(IDbCommand command, LoggingEvent loggingEvent) 
    at log4net.Appender.AdoNetAppender.SendBuffer(IDbTransaction dbTran, LoggingEvent[] events) 
    at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) 

下面是從web.config代碼:

<commandText value="INSERT INTO WebTeamAdminAppLog ([ID],[Date],[Application],[Server],[ProcessId],[Login],[Thread],[Level],[Logger],[Message],[Exception],[SessionId]) VALUES (@logId,@log_date,@app,@server,@processId,@login,@thread,@log_level,@logger,@message,@exception,@sessionid)" /> 
    <parameter> 
    <parameterName value="@logId" /> 
    <dbType value="Guid" /> 
    <layout type="log4net.Layout.RawPropertyLayout"> 
     <key value="logId" /> 
    </layout> 
    </parameter> 

不知道是什麼問題,因爲這段代碼來自另一個將日誌插入數據庫的項目。它是相同的數據庫,只是一個不同的表。另一個應用程序中的log4net版本是1.2.13.0。此外,當我通過調試器,logId值似乎設置正確。

回答

0

檢查你的代碼,如果你有這樣的事情:

Guid id = Guid.NewGuid(); 
var loggingEvent = new LoggingEvent(.....) 
loggingEvent.Properties["logId"] = id; 
+0

我有一些非常相似的東西:Guid guid = Guid.NewGuid(); log4net.ThreadContext.Properties [「logId」] = guid; – ADH

+1

嘗試更新至版本1.2.15。這似乎是版本1.2.14的問題。檢查:https://issues.apache.org/jira/browse/LOG4NET-489?jql=text%20~%20%22An%20SqlParameter%20with%20ParameterName%20is%20not%20contained%20by%20this%20SqlParameterCollection%22 –

+0

我降級到1.2.13。錯誤消失了。 – ADH