我无法让 log4net 工作,并且为 log4net 安装了 Glimpse,我注意到 log4net 选项卡是灰色的,所以我想我没有正确安装它,但不确定在哪里。
在我的 assemblyInfo.cs 中,我有:
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
可能没有必要,但在 Global.asax.cs 我有:
var logConfigFilePath = Server.MapPath("~/log4net.config");
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(logConfigFilePath));
在我的 log4net.config 我有:
?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection,
System.Data, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="data source=SQL_Mulalley;initial catalog=LogFiles;Persist Security Info=True;User ID=***;Password=****;MultipleActiveResultSets=True" providerName="System.Data.SqlClient"/>
<commandText value="INSERT INTO SCD4_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>
<root>
<level value="FATAL"/>
<appender-ref ref="RollingFileAppender"/>
</root>
</log4net>
</configuration>
我在这里获取记录器:
private static readonly log4net.ILog log =
log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
我在我的代码中调用日志如下:
log.Info(string.Format("User {0} logged in.", model.UserName));
在我创建标准 Log4Net 表的数据库中没有出现任何内容。
那么我错过了什么?