I am getting the following error in the log4net error log:
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)
Here is the code from the 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>
Not sure what the problem is since this code is from another project that inserts logs into the database just fine. It is the same database, just a different table. The version of log4net in the other application is 1.2.13.0. Also, when I step through the debugger, the logId value seems to be getting set correctly.