最佳答案
我使用 log4net.Appender. AdoNetAppender Appender。
我的 log4net 表是以下字段 [Date],[Thread],[Level],[Logger],[Message],[Exception]
我需要向 log4net 表中添加另一个字段(例如 SalesId) ,但是如何在 xml 和代码中指定在记录错误或信息消息时记录“ SalesId”?
例如 log.Info("SomeMessage", SalesId)
下面是 log4net xml
<appender name="SalesDBAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value ="System.Data.SqlClient.SqlConnection" />
<connectionString value="Data Source=..." />
<commandText value="INSERT INTO Log4Net ([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>