You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Amit Viraktamath (JIRA)" <ji...@apache.org> on 2009/07/13 22:11:14 UTC

[jira] Created: (LOG4NET-224) After implementing Log4net the application works fine but cannot see the log file created

After implementing Log4net the application works fine but cannot see the log file created
-----------------------------------------------------------------------------------------

                 Key: LOG4NET-224
                 URL: https://issues.apache.org/jira/browse/LOG4NET-224
             Project: Log4net
          Issue Type: Task
         Environment: Windows Server 2003, .NET 3.5
            Reporter: Amit Viraktamath


Hi,

I have created a wrapper to the Log4net and used in my SharePoint webpart. I am developing in .NET 3.5 framework on windows server 2003 platform. After I deploy my webpart the web part works fine. however the logfine is not seen at the configured path. Also there are no errors in the event viewer. Could you please review the following code and suggest what is missing?
WEB.CONFIG file entries

 <configSections>
 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0"/>
 </configSections>

<log4net>
    <logger name="Log4netLoggingFramework">
      <level value="INFO"/>

    </logger>
    <root>
      <level value="INFO" />
      <appender-ref ref="LogFileAppender" />
      <appender-ref ref="ConsoleAppender" />
    </root>
    <appender name="LogFileAppender"
             type="log4net.Appender.FileAppender" >
      <param name="File" value="C:\Inetpub\wwwroot\wss\VirtualDirectories\31569\logfile.log" />
      <param name="AppendToFile" value="true" />
      <layout type="log4net.Layout.PatternLayout">
        <param name="Header" value="[Header]\r\n"/>
        <param name="Footer" value="[Footer]\r\n"/>
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x]&lt;%X{auth}&gt; - %m%n"/>   
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value="INFO" />
        <param name="LevelMax" value="WARN" />
      </filter>
    </appender>
    <appender name="ConsoleAppender"
              type="log4net.Appender.ConsoleAppender" >
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] &lt;%X{auth}&gt; - %m%n" />      
      </layout>
    </appender>
  </log4net>

Following is the C# code that wraps the requests to Log4net dll
--- CODE START --
namespace Log4netLoggingFramework
{
    public static class LogInfo
    {
        public enum LogType { Debug = 1, Error = 2, Info = 3, Fatal = 4};
        public static void Log(string logMessage, int logType)
        {
            //if (logType == LogType.Debug)
            //{
            //    DebugLog dlog = new DebugLog();
            //    dlog.DoLogging(logMessage);
            //}
            //else if (logType == LogType.Info)
            //{
            //    InfoLog ilog = new InfoLog();
            //    ilog.DoLogging(logMessage);
            //}
            //else if (logType == LogType.Error)
            //{
            //    ErrorLog elog = new ErrorLog();
            //    elog.DoLogging(logMessage);
            //}

            if (logType == 1)
            {
                DebugLog dlog = new DebugLog();
                dlog.DoLogging(logMessage);
            }
            else if (logType == 2)
            {
                InfoLog ilog = new InfoLog();
                ilog.DoLogging(logMessage);
            }
            else if (logType == 3)
            {
                ErrorLog elog = new ErrorLog();
                elog.DoLogging(logMessage);
            }
        }
    }

    public class DebugLog
    {
        private static readonly ILog logger =
                LogManager.GetLogger(typeof(DebugLog));

        /// <summary>
        /// Constructor for the DebugLog
        /// </summary>
        static DebugLog()
        {
            XmlConfigurator.Configure();
        }

        /// <summary>
        /// Logs the Info
        /// </summary>
        /// <param name="loginfo"></param>
        public void DoLogging(string loginfo)
        {
            if (logger.IsDebugEnabled)
            {
                logger.Debug(loginfo);
            }

        }
    }  
    public class InfoLog
    {
        private static readonly ILog logger =
                LogManager.GetLogger(typeof(InfoLog));

        /// <summary>
        /// InfoLog Constructor
        /// </summary>
        static InfoLog()
        {
            XmlConfigurator.Configure();
        }

        /// <summary>
        /// Logs the Info Log
        /// </summary>
        /// <param name="logInfo"></param>
        public void DoLogging(string logInfo)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Info(logInfo);

            }

        }

    }
    public class ErrorLog
    {
        private static readonly ILog logger =
                LogManager.GetLogger(typeof(ErrorLog));

        /// <summary>
        /// ErrorLog Constructor
        /// </summary>
        static ErrorLog()
        {
            XmlConfigurator.Configure();
        }

        /// <summary>
        /// Logs teh Errror
        /// </summary>
        /// <param name="logError"></param>
        public void DoLogging(string logError)
        {
            if (logger.IsInfoEnabled)
            {
                logger.Error(logError);
            }

        }

    }
}

--- CODE END ----

Many Thanks,

Amit.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Created: (LOG4NET-224) After implementing Log4net the application works fine but cannot see the log file created

Posted by Brian Browning <bw...@gmail.com>.
Hi,

If log4net is not working a helpful thing to do is to enable the internal
debugging as described in the "How do I enable log4net internal debugging?"
section of the faq at http://logging.apache.org/log4net/release/faq.html

That will usually point you in the direction of what is wrong.

Looking at your config, I would guess that you are using an older version of
log4net? You should make sure you are using the latest version and then
change this line:
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0"/>
to this:
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>

That fixed your code on my machine. Also, this thread should probably go in
the log4net-user mailing list, not in the dev or issue tracker.

Hope that helps!


On Mon, Jul 13, 2009 at 3:11 PM, Amit Viraktamath (JIRA) <ji...@apache.org>wrote:

> After implementing Log4net the application works fine but cannot see the
> log file created
>
> -----------------------------------------------------------------------------------------
>
>                 Key: LOG4NET-224
>                 URL: https://issues.apache.org/jira/browse/LOG4NET-224
>             Project: Log4net
>          Issue Type: Task
>         Environment: Windows Server 2003, .NET 3.5
>            Reporter: Amit Viraktamath
>
>
> Hi,
>
> I have created a wrapper to the Log4net and used in my SharePoint webpart.
> I am developing in .NET 3.5 framework on windows server 2003 platform. After
> I deploy my webpart the web part works fine. however the logfine is not seen
> at the configured path. Also there are no errors in the event viewer. Could
> you please review the following code and suggest what is missing?
> WEB.CONFIG file entries
>
>  <configSections>
>  <section name="log4net"
> type="log4net.Config.Log4NetConfigurationSectionHandler,log4net-net-1.0"/>
>  </configSections>
>
> <log4net>
>    <logger name="Log4netLoggingFramework">
>      <level value="INFO"/>
>
>    </logger>
>    <root>
>      <level value="INFO" />
>      <appender-ref ref="LogFileAppender" />
>      <appender-ref ref="ConsoleAppender" />
>    </root>
>    <appender name="LogFileAppender"
>             type="log4net.Appender.FileAppender" >
>      <param name="File"
> value="C:\Inetpub\wwwroot\wss\VirtualDirectories\31569\logfile.log" />
>      <param name="AppendToFile" value="true" />
>      <layout type="log4net.Layout.PatternLayout">
>        <param name="Header" value="[Header]\r\n"/>
>        <param name="Footer" value="[Footer]\r\n"/>
>        <param name="ConversionPattern" value="%d [%t] %-5p %c
> [%x]&lt;%X{auth}&gt; - %m%n"/>
>      </layout>
>      <filter type="log4net.Filter.LevelRangeFilter">
>        <param name="LevelMin" value="INFO" />
>        <param name="LevelMax" value="WARN" />
>      </filter>
>    </appender>
>    <appender name="ConsoleAppender"
>              type="log4net.Appender.ConsoleAppender" >
>      <layout type="log4net.Layout.PatternLayout">
>        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x]
> &lt;%X{auth}&gt; - %m%n" />
>      </layout>
>    </appender>
>  </log4net>
>
> Following is the C# code that wraps the requests to Log4net dll
> --- CODE START --
> namespace Log4netLoggingFramework
> {
>    public static class LogInfo
>    {
>        public enum LogType { Debug = 1, Error = 2, Info = 3, Fatal = 4};
>        public static void Log(string logMessage, int logType)
>        {
>            //if (logType == LogType.Debug)
>            //{
>            //    DebugLog dlog = new DebugLog();
>            //    dlog.DoLogging(logMessage);
>            //}
>            //else if (logType == LogType.Info)
>            //{
>            //    InfoLog ilog = new InfoLog();
>            //    ilog.DoLogging(logMessage);
>            //}
>            //else if (logType == LogType.Error)
>            //{
>            //    ErrorLog elog = new ErrorLog();
>            //    elog.DoLogging(logMessage);
>            //}
>
>            if (logType == 1)
>            {
>                DebugLog dlog = new DebugLog();
>                dlog.DoLogging(logMessage);
>            }
>            else if (logType == 2)
>            {
>                InfoLog ilog = new InfoLog();
>                ilog.DoLogging(logMessage);
>            }
>            else if (logType == 3)
>            {
>                ErrorLog elog = new ErrorLog();
>                elog.DoLogging(logMessage);
>            }
>        }
>    }
>
>    public class DebugLog
>    {
>        private static readonly ILog logger =
>                LogManager.GetLogger(typeof(DebugLog));
>
>        /// <summary>
>        /// Constructor for the DebugLog
>        /// </summary>
>        static DebugLog()
>        {
>            XmlConfigurator.Configure();
>        }
>
>        /// <summary>
>        /// Logs the Info
>        /// </summary>
>        /// <param name="loginfo"></param>
>        public void DoLogging(string loginfo)
>        {
>            if (logger.IsDebugEnabled)
>            {
>                logger.Debug(loginfo);
>            }
>
>        }
>    }
>    public class InfoLog
>    {
>        private static readonly ILog logger =
>                LogManager.GetLogger(typeof(InfoLog));
>
>        /// <summary>
>        /// InfoLog Constructor
>        /// </summary>
>        static InfoLog()
>        {
>            XmlConfigurator.Configure();
>        }
>
>        /// <summary>
>        /// Logs the Info Log
>        /// </summary>
>        /// <param name="logInfo"></param>
>        public void DoLogging(string logInfo)
>        {
>            if (logger.IsInfoEnabled)
>            {
>                logger.Info(logInfo);
>
>            }
>
>        }
>
>    }
>    public class ErrorLog
>    {
>        private static readonly ILog logger =
>                LogManager.GetLogger(typeof(ErrorLog));
>
>        /// <summary>
>        /// ErrorLog Constructor
>        /// </summary>
>        static ErrorLog()
>        {
>            XmlConfigurator.Configure();
>        }
>
>        /// <summary>
>        /// Logs teh Errror
>        /// </summary>
>        /// <param name="logError"></param>
>        public void DoLogging(string logError)
>        {
>            if (logger.IsInfoEnabled)
>            {
>                logger.Error(logError);
>            }
>
>        }
>
>    }
> }
>
> --- CODE END ----
>
> Many Thanks,
>
> Amit.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>