using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using log4net.Config;
using log4net.Core;
using log4net.Appender;
using log4net.Layout;
using log4net.Repository.Hierarchy;

namespace Foo.Platform
{
    public class Logger
    {        
        static Logger()
        {
            BasicConfigurator.Configure(CreateAndConfigureRollingFileAppender());
        }
   
        /// <summary>
        /// Returns the Log4Net Interface
        /// </summary>
        /// <param name="type">Object Type to pass in to create Logger for</param>
        /// <returns>Log4Net Interface</returns>
        public static ILog GetLog4NetInterface(Type type)
        {
            return LogManager.GetLogger(type);            
        }

        /// <summary>
        /// Creates and Configures teh RollingFileAppender *Configuration goes on here *
        /// </summary>
        /// <returns>RollingFileAppender Class to be used in Configuring Log4Net</returns>
        static private RollingFileAppender CreateAndConfigureRollingFileAppender()
        {
            RollingFileAppender fileAppender = new RollingFileAppender();
            fileAppender.Layout = new PatternLayout(PatternLayout.DetailConversionPattern);
            
            // Locking Minimal allows us to run Log4Net from multiple processes
            fileAppender.LockingModel = new FileAppender.MinimalLock();

            fileAppender.File = (Env.GetLogDirectory() + @"\LogServer.log");
            fileAppender.AppendToFile = true;

            #if DEBUG
                fileAppender.Threshold = Level.All;
            #else
                fileAppender.Threshold = Level.Error;
            #endif

            fileAppender.MaximumFileSize = "5MB";
            fileAppender.MaxSizeRollBackups = 3;
            fileAppender.ActivateOptions();
            return fileAppender;
        }        

    }
}
