0
我的數據庫appender不工作,我不明白爲什麼,連接工作,我已經在sql管理工作室測試appender的命令文本。log4net數據庫appender沒有插入
public class KennyLoggins
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public DateTime Date { get; set; }
public string Thread { get; set; }
public string Level { get; set; }
public string Logger { get; set; }
public string Message { get; set; }
public string Exception { get; set; }
}
我設置跟蹤log4net的,它似乎並沒有得到任何錯誤。
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add
name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="log4net_debug.txt" />
</listeners>
</trace>
</system.diagnostics>
log4net的配置:
<log4net>
<root>
<level value="ALL" />
<appender-ref ref="ADONetAppender" />
</root>
<appender name="ADONetAppender" type="log4net.Appender.ADONetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<connectionString value="Server=.\SQLEXPRESS;Database=MyDB;Integrated Security=True;" />
<commandText value="INSERT INTO KennyLoggins ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
<parameter>
<parameterName value="@log_date"/>
<dbType value="DateTime"/>
<layout type="log4net.Layout.RawTimeStampLayout"/>
</parameter>
<parameter>
<parameterName value="@thread"/>
<dbType value="String"/>
<size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%thread"/>
</layout>
</parameter>
<parameter>
<parameterName value="@log_level"/>
<dbType value="String"/>
<size value="50"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level"/>
</layout>
</parameter>
<parameter>
<parameterName value="@logger"/>
<dbType value="String"/>
<size value="255"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%logger"/>
</layout>
</parameter>
<parameter>
<parameterName value="@message"/>
<dbType value="String"/>
<size value="4000"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message"/>
</layout>
</parameter>
<parameter>
<parameterName value="@exception"/>
<dbType value="String"/>
<size value="2000"/>
<layout type="log4net.Layout.ExceptionLayout"/>
</parameter>
</appender>
</log4net>
我使用我使用實體框架和我的ADONetAppender相同的連接字符串,那會是一個問題?
您的緩衝區大小爲100,這意味着log4net不會寫入日誌事件,直到它們有100個,可以這樣嗎?另外,你是否在你的代碼中初始化log4net? – stuartd