我正在尝试以编程方式覆盖CommandText
. log4net.Appender.AdoNetAppender
当我调试它时,该属性似乎已设置,但插入永远不会终止。
CommandText
值本身肯定是正确的。如果我将它直接粘贴到 Appender 的配置文件中,它会插入记录。我使用多种其他类型的附加程序,它们也可以完成他们的工作。
我应该如何在运行时覆盖该CommandText
属性?
public class DdsAdoNetAppender : AdoNetAppender
{
public new string ConnectionString
{
get
{
return base.ConnectionString;
}
set
{
CommandText = "INSERT INTO ApplicationLogs ([LogDateTime],[LogType],[MachineName],[UserName],[LogMessage],[LogException]) " +
"VALUES (@log_date_time, @log_type, @machine_name, @user_name, @log_message, @log_exception)";
}
}
}
我的 Appender 配置:(commandText 的值基本上是空的。)
<appender name="AdoNetAppender" type="DigitalDrawingStore.Backend.Logging.AdoNetAppenders.DdsAdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<ReconnectOnError value="true" />
<connectionString value="data source = (localdb)\\MSSQLLocalDB; initial catalog = TestAdoNetLogDb; integrated security = true" />
<commandText value="" />
<commandType value="Text" />
<parameter>
<parameterName value="@log_date_time" />
<dbType value="String" />
<layout type="log4net.Layout.PatternLayout" value="%date{yyyy'-'MM'-'dd HH':'mm':'ss'.'fff}" />
</parameter>
<parameter>
<parameterName value="@log_type" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout" value="%property{LogType}" />
</parameter>
<parameter>
<parameterName value="@machine_name" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%property{MachineName}" />
</parameter>
<parameter>
<parameterName value="@user_name" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout" value="%property{UserName}" />
</parameter>
<parameter>
<parameterName value="@log_message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%property{LogMessage}" />
</parameter>
<parameter>
<parameterName value="@log_exception" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout" value="%property{LogException}" />
</parameter>
</appender>