Problem with Log4net

Options
mhcrivera
edited December 2011 in Photon Server
Hello Everyone,

I tried to test the logging framework of Photon by using the Lite Application. I added a line log.Debug("Hello World") inside the Setup() method of the LiteApplication.cs. The Lite.log was created successfully but the "Hello World" line did'nt appear within it. Is there something wrong with my files below? I already made sure that all the dll files and the log4net.config is in the right bin folder.

Here are the contents of my files.

LiteApplication.cs
namespace Lite
{
    using System.IO;
    
    using ExitGames.Logging;
    using ExitGames.Logging.Log4Net;

    using Lite.Diagnostics;

    using log4net.Config;

    using Photon.SocketServer;
    using Photon.SocketServer.Diagnostics;

    /// <summary>
    /// Main photon application. This application is started from the photon server.
    /// This class creates <see cref="LitePeer"/>s for new clients.
    /// Operation dispatch logic is handled by the <see cref="LitePeer"/>. 
    /// </summary>
    public class LiteApplication : ApplicationBase
    {

      
        /// <summary>
        /// Creates a <see cref="LitePeer"/> to handle <see cref="OperationRequest"/>s.
        /// </summary>
        /// <param name="initRequest">
        /// The initialization request.
        /// </param>
        /// <returns>
        /// A new <see cref="LitePeer"/> instance.
        /// </returns>
        protected override PeerBase CreatePeer(InitRequest initRequest)
        {
            return new LitePeer(initRequest.Protocol, initRequest.PhotonPeer);
        }
        
        /// <summary>
        /// Application initializtion.
        /// </summary>
        protected override void Setup()
        {
            


            // log4net
            string path = Path.Combine(this.BinaryPath, "log4net.config");
            var configFile = new FileInfo(path);
            if (configFile.Exists)
            {
                LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
            
                XmlConfigurator.ConfigureAndWatch(configFile);
            }
          
            // counters for the photon dashboard
            CounterPublisher.DefaultInstance.AddStaticCounterClass(typeof(Counter), "Lite");

            Protocol.AllowRawCustomValues = true;
            log.Debug("Hellow World");
        }
        

       

        /// <summary>
        /// Called when the server shuts down.
        /// </summary>
        protected override void TearDown()
        {
        }
    }
}

log4net.config
<?xml version="1.0" encoding="utf-8" ?>
<log4net debug="true">

  <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p %-30.30c{2} %m% [%t] [%x]%n" />
    </layout>
  </appender>
  
	<!-- "normal" log file appender -->
	<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
		<param name="File" value="log\Lite.log" />
		<param name="AppendToFile" value="true" />
		<param name="MaxSizeRollBackups" value="1" />
		<param name="MaximumFileSize" value="250MB" />
		<param name="RollingStyle" value="Size" />
    <param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
		<layout type="log4net.Layout.PatternLayout">
			<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n" />
		</layout>
	</appender>

  <!-- performance counter log file appender -->
  <appender name="CounterAppender" type="log4net.Appender.RollingFileAppender">
    <param name="File" value="log\LiteCounter.log" />
    <param name="AppendToFile" value="true" />
    <param name="MaxSizeRollBackups" value="1" />
    <param name="MaximumFileSize" value="1MB" />
    <param name="RollingStyle" value="Size" />
    <param name="StaticLogFileName" value="true" />
    <param name="LockingModel" type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <param name="ConversionPattern" value="%d{ABSOLUTE} %m%n" />
    </layout>
  </appender>

  <!-- logger -->
  <root>
    <level value="INFO" />
    <appender-ref ref="LogFileAppender" /> 
    <appender-ref ref="ConsoleAppender" />
	</root>

  <!-- operation data logger -->
  <!-- set level to DEBUG to enable operation data logging-->
  <logger name="OperationData" additivity="false">
    <level value="INFO" />
    <appender-ref ref="LogFileAppender" />
  </logger>
  
  <!-- performance counter logger -->
  <!-- set level to DEBUG to enable performance counter logging-->
  <logger name="PerformanceCounter" additivity="false">
    <level value="INFO" />
    <appender-ref ref="CounterAppender" />
  </logger>
  
</log4net>


Output of Lite.log
2011-12-13 23:28:55,022 [1] INFO  Photon.SocketServer.ApplicationBase [(null)] - Application is stopping: AppId=Lite
2011-12-13 23:28:55,027 [1] INFO  PhotonHostRuntime.PhotonDomainManager [(null)] - Stop
2011-12-13 23:28:55,029 [1] INFO  Photon.SocketServer.ApplicationBase [(null)] - Application stop: AppId=Lite
2011-12-13 23:29:51,295 [1] INFO  Photon.SocketServer.ApplicationBase [(null)] - Application start: AppId=Lite; AppPath=C:\Users\MacMac\Desktop\LayaPhotonServer\Photon 3\deploy\Lite
2011-12-13 23:29:51,417 [1] INFO  Photon.SocketServer.Diagnostics.CounterPublisher [(null)] - CounterPublisher started on: 255.255.255.255:40001

I tried to search for solutions on the forums but I haven't seen one.

Thanks,
Mark

Comments

  • dragagon
    Options
    I must be missing where you created the log variable. Normally what I have to do is this:
    public abstract class MasterServer : ApplicationBase
        {
            #region Constants and Fields
    
            protected static readonly ILogger Log = LogManager.GetCurrentClassLogger();
    
            #endregion
    
            #region Overrides of ApplicationBase
    
            protected override void Setup()
            {
                LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance);
                GlobalContext.Properties["LogFileName"] = ApplicationName;
                XmlConfigurator.ConfigureAndWatch(new FileInfo(Path.Combine(BinaryPath, "log4net.config")));
    
                Log.DebugFormat("Hello World");
            }
    
            protected override void TearDown()
            {
            }
        }
    }
    

    You are merely missing the creation of the Log variable from the LogManager.