我正在使用如下的log4net.Info方法,
public static void Audit(this ILog logger, string name, string field)
{
GlobalContext.Properties["Name"] = name;
logger.Info(string.Format(CultureInfo.InvariantCulture, @"AUDIT: {0}", field));
}
我有log4net配置,
<appender name="DatabaseAuditLogAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=localt;Initial Catalog=TestDB;Integrated Security=True;MultipleActiveResultSets=True" />
<commandText value="INSERT INTO [dbo].[__AuditLog]
([CreateOnDateTime],[CreateByUserId],[Name],[Field])
VALUES (@logdate, @CreateByUserId, @Name, @Field)" />
<parameter>
<parameterName value="@logdate" />
<dbType value="DateTime2" />
<size value="-1" />
<layout type="log4net.Layout.RawTimeStampLayout" />
</parameter>
<parameter>
<parameterName value="@CreateByUserId" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{CreateByUserId}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Name" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{Name}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Field" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<threshold value="INFO" />
<filter type="log4net.Filter.StringMatchFilter">
<stringToMatch value="AUDIT:" />
</filter>
<filter type="log4net.Filter.DenyAllFilter" />
</appender>
在这里,当我写日志时,它会像这样写,
Audit: Some messages
我只想删除&#34;审核:&#34;消息中的文字,请帮帮我。
答案 0 :(得分:0)
将您的记录方法更改为:
public static void Audit(this ILog logger, string name, string field)
{
GlobalContext.Properties["Name"] = name;
logger.Info(string.Format(CultureInfo.InvariantCulture, @"{0}", field));
}
(从你的字符串中删除了AUDIT:部分)