我试图将每100条记录输入数据库。如果我将缓冲区大小指定为100.它仍然将每条记录输入数据库。是否有一种方法可以指定刷新间隔和缓冲区大小。那。
这是我的配置。
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="10" />
<connectionType value="System.Data.SqlClient.SqlConnection,
System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=;User ID=;Password=" />
<commandText value="INSERT INTO Errorlog ([clientname],[username],[administration],[selectedentity],[project],[Date],[Thread],[Level],[Logger],
[Message],[Exception],[browser],[ipaddress],[url],[errormessage]) VALUES (@clientname,@username,@administration,@selectedentity,@project,@log_date, @thread, @log_level,
@logger, @message, @exception,@browser,@ipaddress,@url,@errormessage)"/>
<parameter>
<parameterName value="@clientname" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{clientname}" />
</layout>
</parameter>
<parameter>
<parameterName value="@username" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{username}" />
</layout>
</parameter>
<parameter>
<parameterName value="@administration" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{administration}" />
</layout>
</parameter>
<parameter>
<parameterName value="@selectedentity" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{selectedentity}" />
</layout>
</parameter>
<parameter>
<parameterName value="@project" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{project}" />
</layout>
</parameter>
<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>
<parameter>
<parameterName value="@browser" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{browser}" />
</layout>
</parameter>
<parameter>
<parameterName value="@ipaddress" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{ipaddress}" />
</layout>
</parameter>
<parameter>
<parameterName value="@url" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{url}" />
</layout>
</parameter>
<parameter>
<parameterName value="@errormessage" />
<dbType value="String" />
<size value="255" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{errormessage}" />
</layout>
</parameter>
</appender>
<root>
<appender-ref ref="AdoNetAppender"/>
</root>
</log4net>
最佳答案
Buffersize
仅指定在提交之前应在RAM中保留多少个项目。它没有定义记录器的Lossy性质。
要定义有损记录器,您需要明确声明并定义可能丢失的内容:
<lossy value="true"/>
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="ERROR" />
</evaluator>
关于c# - Log4net缓冲区大小不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30630952/