/// <summary>
        /// Sets up the logging facility for the Plugin, which is powered by .NET
        /// </summary>
        void ConfigureLogging() {

            //Create a rolling log file in the MediaPortal log folder
            log4net.Appender.RollingFileAppender rfa = new log4net.Appender.RollingFileAppender();
            rfa.File = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), @"Team MediaPortal\MediaPortal\log\AcidLookup.log");
            rfa.MaxFileSize = 10 * 1024 * 1024;
            rfa.MaxSizeRollBackups = 5;
            rfa.Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            //add a log match filter to our appender above
            //that will only log AcidLookupPlugin.* loggers
            LoggerMatchFilter sourceFilter = new LoggerMatchFilter();
            sourceFilter.LoggerToMatch = "AcidLookupPlugin";
            rfa.AddFilter(sourceFilter);
            // now add the deny all filter to end of the chain
            DenyAllFilter denyAllFilter = new DenyAllFilter();
            rfa.AddFilter(denyAllFilter);
            // activate the options
            rfa.ActivateOptions();

            ((Logger)log4net.LogManager.GetLogger("AcidLookupPlugin").Logger).AddAppender(rfa);

            //Some plugins may already be using log4net so
            //don't configure it unless it hasn't been configured before
            if (!log4net.LogManager.GetRepository().Configured) {
                log4net.Config.BasicConfigurator.Configure();
            }

            //drop the NHibernate level to Notice
            ((Logger)log4net.LogManager.GetLogger("NHibernate").Logger).Level = Level.Notice;
        }
    private void InitializeLog4Net()
    {
        nativeLogger = log4net.LogManager.GetLogger("UnityLog4NetLogger");

        // set log rotate to daily
        log4net.Appender.RollingFileAppender rollingFileAppender = new log4net.Appender.RollingFileAppender();
        rollingFileAppender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
        rollingFileAppender.AppendToFile      = true;
        rollingFileAppender.StaticLogFileName = false;
        rollingFileAppender.File        = Path.GetFullPath(outputLogDir) + "/";
        rollingFileAppender.DatePattern = "yyyyMMdd\".log\"";
        rollingFileAppender.Layout      = new log4net.Layout.PatternLayout("%date{yyyy/MM/dd  HH:mm:ss} %message%newline");

        log4net.Filter.LevelRangeFilter filter = new log4net.Filter.LevelRangeFilter();
        switch (filterLevel)
        {
        case FILTER_LEVEL.VERBOSE: filter.LevelMin = log4net.Core.Level.Verbose; break;

        case FILTER_LEVEL.DEBUG: filter.LevelMin = log4net.Core.Level.Debug; break;

        case FILTER_LEVEL.INFO: filter.LevelMin = log4net.Core.Level.Info; break;

        case FILTER_LEVEL.WARN: filter.LevelMin = log4net.Core.Level.Warn; break;

        case FILTER_LEVEL.ERROR: filter.LevelMin = log4net.Core.Level.Error; break;
        }
        filter.LevelMax = log4net.Core.Level.Fatal;
        rollingFileAppender.AddFilter(filter);

        rollingFileAppender.ActivateOptions();
        ((log4net.Repository.Hierarchy.Logger)nativeLogger.Logger).AddAppender(rollingFileAppender);
        ((log4net.Repository.Hierarchy.Logger)nativeLogger.Logger).Hierarchy.Configured = true;
    }
Example #3
0
    public Logging(string sFileName, string sLocation, bool bUseLogging)
    {
        m_sFileName = sFileName;
        if (!bUseLogging)
        {
            return;
        }

        if (sLocation.Length > 0)
        {
            if (sLocation[sLocation.Length - 1] != '\\')
            {
                sLocation += "\\";
            }
        }

        m_RFL      = new log4net.Appender.RollingFileAppender();
        m_RFL.File = sLocation + m_sFileName + m_sFileExt;
        m_RFL.StaticLogFileName  = true;
        m_RFL.AppendToFile       = true;
        m_RFL.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size;
        m_RFL.MaximumFileSize    = "10mb";
        m_RFL.MaxSizeRollBackups = 2;
        m_RFL.Threshold          = log4net.Core.Level.All;

        //m_RFL.CountDirection = 1;
        //m_RFL.DatePattern = "HH:MM::SS";
        log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%message%newline");
        layout.ActivateOptions();
        log4net.Filter.LevelRangeFilter filter = new log4net.Filter.LevelRangeFilter();
        filter.LevelMax = log4net.Core.Level.Emergency;
        filter.LevelMin = log4net.Core.Level.All;
        m_RFL.AddFilter(filter);
        m_RFL.Layout = layout;
        m_RFL.ActivateOptions();

        log4net.Config.BasicConfigurator.Configure(m_RFL);

        // Set up
        Log(Logging.LOGTYPE.ERROR, "Start logging...");
    }
Example #4
0
    private void InitializeLog4Net()
    {
        // ログローテーション設定
        nativeLogger = log4net.LogManager.GetLogger("Logger");

        log4net.Appender.RollingFileAppender rollingFileAppender = new log4net.Appender.RollingFileAppender();
        rollingFileAppender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
        rollingFileAppender.AppendToFile      = true;
        rollingFileAppender.StaticLogFileName = false;
        rollingFileAppender.File        = Path.GetFullPath(outputLogDir) + "/";
        rollingFileAppender.DatePattern = "yyyyMMdd\".log\"";
        rollingFileAppender.Layout      = new log4net.Layout.PatternLayout("%date{yyyy/MM/dd  HH:mm:ss} %message%newline");
        log4net.Filter.LevelRangeFilter filter = new log4net.Filter.LevelRangeFilter();
        filter.LevelMin = log4net.Core.Level.Info;
        filter.LevelMax = log4net.Core.Level.Fatal;
        rollingFileAppender.AddFilter(filter);

        rollingFileAppender.ActivateOptions();
        ((log4net.Repository.Hierarchy.Logger)nativeLogger.Logger).AddAppender(rollingFileAppender);
        ((log4net.Repository.Hierarchy.Logger)nativeLogger.Logger).Hierarchy.Configured = true;
    }
Example #5
0
        static log4net.Appender.RollingFileAppender GetFileAppender(string name, log4net.Core.Level max, log4net.Core.Level min)
        {
            //设置过滤器
            log4net.Filter.LevelRangeFilter _levfilter = new log4net.Filter.LevelRangeFilter();
            _levfilter.LevelMax = max;
            _levfilter.LevelMin = min;
            _levfilter.ActivateOptions();

            //设计记录格式
            log4net.Layout.PatternLayout _layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level - %message%newline");

            //Appender1
            log4net.Appender.RollingFileAppender _appender = new log4net.Appender.RollingFileAppender();
            //设置本Appander的名称
            _appender.Name = m_initTime.ToString("HHmmss") + "." + name + ".Appender";
            _appender.File = GetLogSavePath() + name + ".log";
            //否追加到文件
            _appender.AppendToFile       = true;
            _appender.MaxSizeRollBackups = 10;
            //日志文件名是否为静态
            _appender.StaticLogFileName = true;
            //_appender.DatePattern = "";
            //表示是否立即输出到文件,布尔型的。
            //_appender.ImmediateFlush
            //SecurityContext : 比较少应用,对日志进行加密只类的,使用SecurityContextProvider转换。(对日志的保密要求比较高的时候应该可以应用上吧,Log4考虑的还挺周全)
            //LockingModel : 文件锁类型,RollingFileAppender本身不是线程安全的,如果在程序中没有进行线程安全的限制,可以在这里进行配置,确保写入时的安全。有两中类型:FileAppender.ExclusiveLock 和 FileAppender.MinimalLock

            _appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
            //_appender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();

            _appender.Layout = _layout;
            _appender.AddFilter(_levfilter);
            _appender.ActivateOptions();

            return(_appender);
        }