我通过log4net登录到数据库时出现问题。
获得以下配置:
<log4net debug="true">
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file type="log4net.Util.PatternString" value="Logs\JallaJalla (%date{yyyyMMdd HHmmss}).log" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date %logger %-5level - %message%newline" />
</layout>
</appender>
<appender name="ADONetAppender" type="log4net.Appender.AdoNetAppender">
<threshold value="DEBUG"/>
<bufferSize value="1" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source=xxx;Initial Catalog=xxx;User Id=xxx;Password=xxx;" />
<commandText value="INSERT INTO [log].[tLogTable] ([Message],[Level]) VALUES (@message, @log_level)" />
<parameter>
<parameterName value="@message" />
<dbType value="String" />
<size value="4000" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message" />
</layout>
</parameter>
<parameter>
<parameterName value="@log_level" />
<dbType value="String" />
<size value="50" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%level" />
</layout>
</parameter>
</appender>
<logger name="ADONetAppender">
<level value="ALL" />
<appender-ref ref="ADONetAppender" />
</logger>
<logger name="FileLogger">
<level value="ALL" />
<appender-ref ref="FileAppender" />
</logger>
</log4net>
DB中的两列是:
谢谢!
答案 0 :(得分:1)
我自己发现了这个问题......
private static readonly ILog Logger = LogManager.GetLogger( "FileLogger" );
记录器的名称设置为“FileLogger” 所以加入
<appender-ref ref="ADONetAppender" />
里面
<logger name="FileLogger">
<level value="ALL" />
<appender-ref ref="FileAppender" />
<appender-ref ref="ADONetAppender" />
</logger>
解决了这个问题!
非常感谢!
答案 1 :(得分:0)
我猜您忘记将以下内容添加到您想要启用日志记录的assamblies:
[assembly: log4net.Config.XmlConfigurator()]
或来自代码:
log4net.Config.XmlConfigurator.Configure();