C# · 12月 26, 2021

c# – 在log4net AdoNetAppender中延迟记录?

我有一个这样的AdoNetAppender设置: <log4net> <appender name=”AdoNetAppender_sqlServer” type=”log4net.Appender.AdoNetAppender”> <connectionStringName value=”DefaultConnection” /> <connectionType value=”System.Data.sqlClient.sqlConnection,System.Data,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089″ /> <commandText value=”INSERT INTO Log ([Date],[Thread],[Level],[Logger],[Message]) VALUES (@log_date,@thread,@log_level,@logger,@message)” /> <useTransactions value=”false” /> <parameter> <parameterName value=”@log_date” /> <dbType value=”DateTime” /> <layout type=”log4net.Layout.PatternLayout” value=”%date{yyyy’-‘MM’-‘dd HH’:’mm’:’ss’.’fff}” /> </parameter> <parameter> <parameterName value=”@thread” /> <dbType value=”String” /> <size value=”255″ /> <layout type=”log4net.Layout.PatternLayout” value=”%thread” /> </parameter> <parameter> <parameterName value=”@log_level” /> <dbType value=”String” /> <size value=”50″ /> <layout type=”log4net.Layout.PatternLayout” value=”%level” /> </parameter> <parameter> <parameterName value=”@logger” /> <dbType value=”String” /> <size value=”255″ /> <layout type=”log4net.Layout.PatternLayout” value=”%logger” /> </parameter> <parameter> <parameterName value=”@message” /> <dbType value=”String” /> <size value=”4000″ /> <layout type=”log4net.Layout.PatternLayout” value=”%message” /> </parameter> </appender> <root> <level value=”DEBUG” /> <appender-ref ref=”AdoNetAppender_sqlServer” /> </root> </log4net>

而且在技术上它是有效的,因为当我停止在本地的IIS 8 Express上运行的网站时,记录显示.然而,这正是问题,记录在我停止网站之前不显示.

我已经尝试用onTransactions打开和关闭.

有人可以帮忙吗

解决方法 尝试将缓冲区大小设置为1: <appender name=”AdoNetAppender_sqlServer” type=”log4net.Appender.AdoNetAppender”> <connectionStringName value=”DefaultConnection” /> <connectionType value=”System.Data.sqlClient.sqlConnection,@message)” /> <useTransactions value=”false” /> <bufferSize value=”1″ />

更多细节:http://weblogs.asp.net/drnetjes/archive/2005/02/16/374780.aspx