记录器无法正常工作

时间:2013-05-28 07:31:09

标签: logging log4net

在我的类库中,使用Log4net获取日志。已创建日志文件,但未记录日志。帮助获取日志....下面是我的App.Config和ClassLibrary。 它只是在C:驱动器中创建一个文本文件“TestLog1.txt”。但是没有记录日志......

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,  
         log4net" />
 </configSections>

 <log4net debug="true">
 <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
   <file value="C:\\TestLog1.txt" />
   <appendToFile value="true" />
   <rollingStyle value="Size" />
   <maxSizeRollBackups value="5" />
   <maximumFileSize value="5MB" />
   <staticLogFileName value="true" />
   <layout type="log4net.Layout.PatternLayout">

      <conversionPattern value="%date{absolute} , [%thread] , %level , %logger , %method , %l , %message %n" />

   </layout>
 </appender>
 <root>
   <level value="INFO"/>
   <appender-ref ref="RollingFileAppender" />
 </root>
 <appSettings>
    <!-- <add key="log4net.Internal.Debug" value="true" />-->
  </appSettings>
 </log4net>
</configuration>

ClassLibrary.cs

using log4net;
using log4net.Config;


[assembly: log4net.Config.XmlConfigurator(Watch=true)]


namespace SampleClassLibrary
{
   public class DbServices
    {

       private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);


    public DataSet Get_Login(string User,string Pwd)
    {
        log.Info("Entering Get_Login method");

    }

1 个答案:

答案 0 :(得分:0)

首先,您的配置不正确,appSettings不是log4net配置的一部分。查看Configuration documentation将配置更改为单独的文件,而不是web.config。并将<add key="log4net.Internal.Debug" value="true" />添加到您的appsettings以进行内部调试。