在過去的幾個小時裏,我一直在試圖讓日誌寫入數據庫的表中。Log4net不會寫入數據庫
開啓調試後,我收到以下錯誤語句:SqlCommand.Prepare方法要求所有可變長度參數有一個明確設置非零大小
這裏是我的代碼片段:
配置部分:
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net"/>
</configSections>
<log4net>
<root>
<level value="ALL"/>
<appender-ref ref="loginLog"/>
<appender-ref ref="maskyooLog"/>
<appender-ref ref="bpelLog"/>
</root>
<appender name="bpelLog" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="server=***; uid=***; pwd=****; database=***" />
<commandText value="INSERT INTO dbo.BPELLog ([UserName], [ProcessModeID], [CcCompanyNameID], [CcExpDate],
[CcID], [CcOwnerID], [CcOwnerName], [InvoiceDate], [CustomerNo],
[SumWithDue], [SumWithoutDue], [PaymentTypeID], [TaxRegistrationNum], [TrxUniqueID], [SalesPerson])
VALUES (@UserName, @ProcessModeID, @CcCompanyNameID, @CcExpDate, @CcID, @CcOwnerID, @CcOwnerName,
@InvoiceDate, @CustomerNo, @SumWithDue, @SumWithoutDue, @PaymentTypeID,
@TaxRegistrationNum, @TrxUniqueID, @SalesPerson)" />
<parameter>
<parameterName value="@InvoiceDate" />
<dbType value="DateTime" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@ProcessModeID" />
<dbType value="Int32" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{ProcessModeID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@PaymentTypeID" />
<dbType value="Int32" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{PaymentTypeID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CustomerNo"/>
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CustomerNo}" />
</layout>
</parameter>
<parameter>
<parameterName value="@TaxRegistrationNum"/>
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{TaxRegistrationNum}" />
</layout>
</parameter>
<parameter>
<parameterName value="@SalesPerson"/>
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{SalesPerson}" />
</layout>
</parameter>
<parameter>
<parameterName value="@TrxUniqueID"/>
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{TrxUniqueID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CcOwnerName" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CcOwnerName}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CcOwnerID" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CcOwnerID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CcID" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CcID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CcExpDate" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CcExpDate}" />
</layout>
</parameter>
<parameter>
<parameterName value="@UserName" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{UserName}" />
</layout>
</parameter>
<parameter>
<parameterName value="@CcCompanyNameID" />
<dbType value="Int32" />
<size value="15" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CcCompanyNameID}" />
</layout>
</parameter>
<parameter>
<parameterName value="@SumWithoutDue" />
<dbType value="decimal" />
<size value="20" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{SumWithoutDue}" />
</layout>
</parameter>
<parameter>
<parameterName value="@SumWithDue" />
<dbType value="decimal" />
<size value="20" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{SumWithDue}" />
</layout>
</parameter>
</appender>
和類:
ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
log4net.Config.XmlConfigurator.Configure();
log4net.Util.SystemInfo.NullText = null;
GlobalContext.Properties["UserName"] = userName;
GlobalContext.Properties["ProcessModeID"] = processModeId;
GlobalContext.Properties["CcCompanyNameID"] = ccCompanyNameId;
GlobalContext.Properties["CcExpDate"] = cCExpDate;
GlobalContext.Properties["CcID"] = ccId;
GlobalContext.Properties["CcOwnerID"] = ccOwnerId;
GlobalContext.Properties["CcOwnerName"] = ccOwnerName;
GlobalContext.Properties["InvoiceDate"] = invoiceDate;
GlobalContext.Properties["CustomerNo"] = customerNo;
GlobalContext.Properties["SumWithDue"] = sumWithDue;
GlobalContext.Properties["SumWithoutDue"] = sumWithoutDue;
GlobalContext.Properties["PaymentTypeID"] = paymentTypeId;
GlobalContext.Properties["TaxRegistrationNum"] = taxRegistrationNum;
GlobalContext.Properties["TrxUniqueID"] = trxUniqueId;
GlobalContext.Properties["SalesPerson"] = salesPerson;
log.Debug(string.Format("UserName: {0}, ProcessModeID: {1}, CcCompanyNameID: {2}, CcExpDate: {3}, CcID: {4}, CcOwnerID: {5}, InvoiceDate: {6}, CustomerNo: {7}, SumWithDue: {8}, SumWithoutDue: {9}, PaymentTypeID: {10},"
+ "TaxRegistrationNum: {11}, TrxUniqueID: {12}, SalesPerson: {13}", userName, processModeId, ccCompanyNameId, cCExpDate, ccId, ccOwnerId, ccOwnerName, invoiceDate, customerNo, sumWithDue, sumWithoutDue,
paymentTypeId, taxRegistrationNum, trxUniqueId, salesPerson));
「輸出」窗口中未顯示任何錯誤。
任何幫助,將不勝感激。
嘗試打開內部調試,看看會發生什麼:http://stackoverflow.com/questions/756125/how-to-track-down-log4net-problems –
嘿,對於遲到的回覆抱歉,我已經變成了調試並收到以下錯誤:SqlCommand.Prepare方法要求所有可變長度參數有一個顯式設置非零大小 –