简体   繁体   中英

Logger is not working

In my Class library, am using Log4net to get the logs. The Log file is been created, but no logs were recorded in it. Help to get logs.... Given below my App.Config and ClassLibrary. Its just creating a text file as "TestLog1.txt" in the C: drive . But no logs were recorded in it...

<?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");

    }

First of all your config is not correct, the appSettings is not part of the log4net configuration. Have a look at the Configuration documentation to change your config to a sepperate file, instead of your web.config. And add the <add key="log4net.Internal.Debug" value="true" /> to you appsettings for internal debugging.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM