/// <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;
        }
Ejemplo n.º 2
1
        /// <summary>
        /// Configure Log4Net
        /// </summary>
        public void Log4NetConfig(bool isConsoleEnabled, string traceFilePath)
        {
            if (isConsoleEnabled)
            {
                // Add console output
                log4net.Appender.ConsoleAppender ca = new log4net.Appender.ConsoleAppender();
                ca.Layout = new log4net.Layout.PatternLayout("%-5level %message%newline");
                ca.Threshold = log4net.Core.Level.All;
                log4net.Config.BasicConfigurator.Configure(ca);
                ca.ActivateOptions();
            }

            if (traceFilePath != "")
            {
                // Add file output
                log4net.Appender.RollingFileAppender rfa = new log4net.Appender.RollingFileAppender();
                rfa.AppendToFile = true;
                rfa.File = traceFilePath;
                rfa.MaxFileSize = 4096000;
                rfa.MaxSizeRollBackups = 2;
                rfa.Threshold = log4net.Core.Level.All;
                rfa.Layout = new log4net.Layout.PatternLayout("%-5level %date{HH:mm:ss,fff} " +
                                                              "[%thread] %logger (%file:%line) " +
                                                              "%newline%message%newline%newline");
                log4net.Config.BasicConfigurator.Configure(rfa);
                rfa.ActivateOptions();
            }

            // Set Root level
            log4net.Repository.Hierarchy.Hierarchy h =
                (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository ();
              		log4net.Repository.Hierarchy.Logger rootLogger = h.Root;
            rootLogger.Level = log4net.Core.Level.All;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 
        /// </summary>
        public static void InitLog4Net()
        {
            var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();

            hierarchy.Configured = true;

            var rollingAppender = new log4net.Appender.RollingFileAppender
            {
                File = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" +
                string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ".log",
                AppendToFile = true,
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                DatePattern = "_yyyyMMdd-hh\".log\"",
              
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            var traceAppender = new log4net.Appender.TraceAppender()
            {
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            hierarchy.Root.AddAppender(rollingAppender);
            hierarchy.Root.AddAppender(traceAppender);
            rollingAppender.ActivateOptions();

            hierarchy.Root.Level = log4net.Core.Level.All;  
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 动态改变日志文件的纪录路径
 /// </summary>
 public static void ChangeRollingFilePath(string logPath)
 {
     if (IsLoaded)
     {
         return;
     }
     try
     {
         if (!string.IsNullOrEmpty(logPath))
         {
             logPath = Path.Combine(logPath, "ErrorLog");
             if (!Directory.Exists(logPath))
             {
                 Directory.CreateDirectory(logPath);
             }
             log4net.Repository.Hierarchy.Logger root = ((log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository()).Root;
             root.Level = log4net.Core.Level.Debug;
             log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
             string strFilePath = Path.Combine(logPath, "log_system.log");
             appender.File               = strFilePath;
             appender.AppendToFile       = true;
             appender.MaxSizeRollBackups = 5;
             appender.MaximumFileSize    = "1MB";
             appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size;
             appender.StaticLogFileName  = false;
             appender.Encoding           = Encoding.UTF8;
             appender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();
             appender.DatePattern        = "yyyy-MM-dd";
             appender.Layout             = new log4net.Layout.PatternLayout("%date [%thread] %-5level - %message%newline");
             appender.ActivateOptions();
             log4net.Config.BasicConfigurator.Configure(appender);
             IsLoaded = true;
         }
     }
     catch (Exception ex)
     {
         string TempPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
         if (System.IO.Directory.Exists(TempPath))
         {
             TempPath = Path.Combine(TempPath, "imobie");
             TempPath = Path.Combine(TempPath, "ErrorLog");
             if (!System.IO.Directory.Exists(TempPath))
             {
                 Directory.CreateDirectory(TempPath);
             }
             TempPath = Path.Combine(TempPath, "logfile.txt");
             if (File.Exists(TempPath))
             {
                 File.Delete(TempPath);
             }
             FileStream fs1 = File.Create(TempPath);
             fs1.Close();
             StreamWriter sw = new StreamWriter(TempPath, true);
             sw.WriteLine("Create LogFile fail!");
             sw.WriteLine("Create Path:" + (logPath != "" ? logPath : "Null"));
             sw.WriteLine("Failed Messsage:" + ex.Message);
             sw.Close();
         }
     }
 }
Ejemplo n.º 5
0
        public void AddAppender(string appenderName, ILogger wLogger)
        {
            if (!ConfigurationManager.AppSettings.AllKeys.Contains("BackupPath"))
            {
                throw new Exception("Parameter 'BackupPath' is mandatory");
            }

            string filename = ConfigurationManager.AppSettings["BackupPath"].ToString() + "\\" + appenderName + ".sql";

            log4net.Repository.Hierarchy.Logger l = (log4net.Repository.Hierarchy.Logger)wLogger;

            log4net.Appender.IAppender hasAppender = l.GetAppender(appenderName);
            if (hasAppender == null)
            {
                log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                appender.DatePattern       = "yyyyMMdd";
                appender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
                appender.AppendToFile      = true;
                appender.File              = filename;
                appender.StaticLogFileName = true;
                appender.Name              = appenderName;

                log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout();
                layout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
                layout.ActivateOptions();

                appender.Layout = layout;
                appender.ActivateOptions();

                l.AddAppender(appender);
            }
        }
Ejemplo n.º 6
0
        public virtual void InitializeLogger()
        {
            DateTime _DateTime         = DateTime.Now;
            string   _LoggerFolderPath = String.Format(@"{0}\{1:D4}\{2:D2}\{3:D2}\", LogDefaultPath, _DateTime.Year, _DateTime.Month, _DateTime.Day);

            log4net.Repository.Hierarchy.Hierarchy _Hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();
            _Hierarchy.Configured = true;

            log4net.Appender.RollingFileAppender _RollingAppender = new log4net.Appender.RollingFileAppender();
            _RollingAppender.File              = LogDefaultPath + @"\";
            _RollingAppender.AppendToFile      = true;
            _RollingAppender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
            _RollingAppender.LockingModel      = new log4net.Appender.FileAppender.MinimalLock();
            _RollingAppender.StaticLogFileName = false;
            _RollingAppender.DatePattern       = "yyyy\\\\MM\\\\dd\\\\\"LogFile_\"yyyyMMdd\".log\""; // 날짜가 지나간 경우 이전 로그에 붙을 이름 구성
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%d{yyyy/MM/dd-HH:mm:ss:ffff} [%-5level] : %message%newline");
            _RollingAppender.Layout = layout;
            _RollingAppender.ActivateOptions();

            _Hierarchy.Root.RemoveAllAppenders();
            _Hierarchy.Root.AddAppender(_RollingAppender);
            _Hierarchy.Root.Level = log4net.Core.Level.All;

            LogFolderPath = LogDefaultPath;
        }
Ejemplo n.º 7
0
        ILog ConfigLog4Net()
        {
            ///Appender2
            log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();

            appender.AppendToFile       = true;
            appender.File               = "DatFileWatcher.log";
            appender.MaxFileSize        = 5 * 1024 * 1024;
            appender.MaxSizeRollBackups = 2;
            appender.ImmediateFlush     = true;
            appender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();

            appender.Name = "DatFileWatcher";
            ///layout
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level - %message%newline");
            layout.Header   = "------ New session ------" + Environment.NewLine;
            layout.Footer   = "------ End session ------" + Environment.NewLine;
            appender.Layout = layout;
            appender.ActivateOptions();

            log4net.Repository.ILoggerRepository repository = log4net.LogManager.CreateRepository("DatFileWatcher");
            log4net.Config.BasicConfigurator.Configure(repository, appender);
            ILog logger = log4net.LogManager.GetLogger(repository.Name, "Logger");

            return(logger);
        }
        public static void AddRollingFileAppender(string filePath = "logs/log.txt",
                                                  log4net.Core.Level threshold = null,
                                                  string logPattern            = CodeConfiguredUtilities.DefaultLogPattern,
                                                  log4net.Appender.RollingFileAppender.RollingMode rollingMode = log4net.Appender.RollingFileAppender.RollingMode.Date,
                                                  string rollingModeDatePattern = "yyyyMMdd",
                                                  int maxNumberOfLogFilesToKeep = 5)
        {
            // it's cast to a Hierarchy because we need repo.Root to add appenders
            var repo = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();

            var logPatternLayout = new log4net.Layout.PatternLayout(logPattern);

            var fileAppender = new log4net.Appender.RollingFileAppender();

            fileAppender.File               = filePath;
            fileAppender.AppendToFile       = true;
            fileAppender.Layout             = logPatternLayout;
            fileAppender.MaxSizeRollBackups = maxNumberOfLogFilesToKeep; // http://stackoverflow.com/questions/95286/log4net-set-max-backup-files-on-rollingfileappender-with-rolling-date

            fileAppender.RollingStyle = rollingMode;

            if (rollingMode == log4net.Appender.RollingFileAppender.RollingMode.Date && !string.IsNullOrEmpty(rollingModeDatePattern))
            {
                fileAppender.DatePattern = "yyyyMMdd";
            }

            if (threshold != null)
            {
                fileAppender.Threshold = threshold;
            }

            fileAppender.ActivateOptions();
            repo.Root.AddAppender(fileAppender);
        }
Ejemplo n.º 9
0
 /// <summary>
 ///  自定义 花样日志
 /// </summary>
 /// <param name="Name"></param>
 /// <param name="Message"></param>
 /// <param name="DeviceId"></param>
 public static void Info(String Name, String Message, string DeviceId)
 {
     appender.File = string.Format("D:/logs/{0}_{1}.log", DeviceId, DateTime.Now.ToString("yyyyMMdd"));
     appender.ActivateOptions();
     appender.AppendToFile = true;
     appender.Writer.WriteLine(String.Format("{0},{1}-\r\n{2}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Name, Message));
 }
Ejemplo n.º 10
0
        private static void InitConfig()
        {
            if (_ILog == null)
            {
                lock (lockOjbect)
                {
                    if (_ILog == null)
                    {
                        _ILog = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

                        log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                        appender.File = AppDomain.CurrentDomain.BaseDirectory + "\\Log\\" + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";

                        appender.AppendToFile       = true;
                        appender.MaxSizeRollBackups = -1;
                        appender.MaximumFileSize    = "1MB";
                        appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Date;
                        //appender.DatePattern = "yyyyMMdd.txt";
                        appender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
                        appender.Layout       = new log4net.Layout.PatternLayout("%date  - %message%newline");
                        appender.ActivateOptions();
                        appender.Threshold = Level.Info;
                        log4net.Config.BasicConfigurator.Configure(appender);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public static log4net.ILog InitLogging(string logfilename, bool verbose)
        {
            ConsoleLogging = verbose;
            logfilename    = System.Environment.ExpandEnvironmentVariables(logfilename);
            if (verbose)
            {
                Console.WriteLine("Initializing logfile: {0}", logfilename);
            }
            log4net.Appender.ForwardingAppender  appender = new log4net.Appender.ForwardingAppender();
            log4net.Appender.RollingFileAppender rfa      = new log4net.Appender.RollingFileAppender
            {
                AppendToFile       = true,
                LockingModel       = new log4net.Appender.RollingFileAppender.MinimalLock(),
                Layout             = new log4net.Layout.PatternLayout("%date\t%message%newline"),
                File               = logfilename,
                MaxSizeRollBackups = 10,
                MaxFileSize        = 10 * 1024 * 1024,
                RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size,
                DatePattern        = "yyyyMMdd"
            };
            rfa.ActivateOptions();
            appender.AddAppender(rfa);
            if (verbose)
            {
                appender.AddAppender(
                    new log4net.Appender.ConsoleAppender
                {
                    Layout = new log4net.Layout.PatternLayout("%message%newline")
                }
                    );
            }

            log4net.Config.BasicConfigurator.Configure(appender);
            return(log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// intialize file writer
        /// </summary>
        /// <param name="_Filename"></param>
        void InitializeBackupFile(String _Filename)
        {
            try
            {
                if (!String.IsNullOrEmpty(_Filename) && null == m_BackupAppender)
                {
                    String patternStr = "%date : %message%newline";

                    log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(patternStr);

                    log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                    appender.RollingStyle      = log4net.Appender.RollingFileAppender.RollingMode.Date;
                    appender.Layout            = layout;
                    appender.File              = _Filename;
                    appender.DatePattern       = "\"_\"yyyyMMdd\".txt\"";
                    appender.StaticLogFileName = false;
                    appender.ActivateOptions();

                    m_BackupAppender = appender;
                }
            }
            catch (System.Exception ex)
            {
                m_BackupAppender = null;
                Log.Error("初始化备份文件失败.", ex);
            }
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor for this class.
 /// Initializes the log4net wrapper.
 /// </summary>
 static FileLogger()
 {
     m_Appender                = new log4net.Appender.RollingFileAppender();
     m_Appender.Name           = "DebugLog";
     m_Appender.File           = System.IO.Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + System.IO.Path.DirectorySeparatorChar + "DebugLog.txt";
     m_Path                    = m_Appender.File;
     m_Appender.AppendToFile   = true;
     m_Appender.LockingModel   = new log4net.Appender.FileAppender.MinimalLock();
     m_Appender.Layout         = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");
     m_Appender.ImmediateFlush = true;
     m_Appender.Threshold      = log4net.Core.Level.Off;
     m_Appender.RollingStyle   = log4net.Appender.RollingFileAppender.RollingMode.Size;
     m_Appender.MaxFileSize    = m_MaxFileSize;
     try
     {
         m_Appender.ActivateOptions();
     }
     catch (Exception ee)
     {
         string excep = ee.Message;
     }
     log4net.Config.BasicConfigurator.Configure(m_Appender);
     m_Log = log4net.LogManager.GetLogger("DebugLog");
     //foreach (log4net.ILog log in log4net.LogManager.GetCurrentLoggers())
     //{
     //    log4net.Repository.Hierarchy.Logger logger = (log4net.Repository.Hierarchy.Logger)log.Logger;
     //    Debug.WriteLine(String.Format("{0} Parent {1} Level {2} EffectiveLevel {3}<br>", logger.Name, logger.Parent.Name, logger.Level == null ? "<null>" : logger.Level.Name, logger.EffectiveLevel));
     //}
 }
Ejemplo n.º 14
0
    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;
    }
Ejemplo n.º 15
0
        public static void Error(string client, string name, object message)
        {
            //var log = GetLog(string.Format("{0}_Error_{1}", client, name));
            //if (log == null)
            //{
            //    return;
            //}

            //ThreadContext.Properties["logFileName"] = string.Format("{0}_Error_{1}", client, name);
            var log = LogManager.GetLogger(name);


            var h = (log4net.Repository.Hierarchy.Hierarchy)log.Logger.Repository;

            var list = LogManager.GetRepository().GetAppenders();


            foreach (log4net.Appender.IAppender a in h.GetAppenders())
            {
                if (a.Name == "LogFileAppender")
                {
                    log4net.Appender.RollingFileAppender fa = (log4net.Appender.RollingFileAppender)a;

                    fa.File = string.Format(@"D:\{0}\", @"DEBUG\ERROR");
                    fa.ActivateOptions();
                }
            }

            log.Error(message);
        }
Ejemplo n.º 16
0
        private string GenerateCurrentLog4NetRepository()
        {
            string result = "";

            ///Appender
            log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();

            appender.AppendToFile       = true;
            appender.File               = this.logPath + "\\" + this.logName;
            appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Composite;
            appender.DatePattern        = ".dd";
            appender.MaxSizeRollBackups = 100;
            appender.MaximumFileSize    = "100MB";
            appender.CountDirection     = 1;
            appender.ImmediateFlush     = true;
            appender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();

            ///layout
            //log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%message%newline");
            log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%-5level:%message%newline");
            layout.Header = "------ New session ------" + Environment.NewLine;
            layout.Footer = "------ End session ------" + Environment.NewLine;
            //
            appender.Layout = layout;
            appender.ActivateOptions();
            //
            log4net.Repository.ILoggerRepository repository = log4net.LogManager.CreateRepository(this.logName + "Repository");
            log4net.Config.BasicConfigurator.Configure(repository, appender);
            result = repository.Name;

            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        public static void InitLog4Net()
        {
            var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();

            hierarchy.Configured = true;

            var rollingAppender = new log4net.Appender.RollingFileAppender
            {
                File = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\" +
                       string.Format("{0:yyyy-MM-dd}", DateTime.Now) + ".log",
                AppendToFile = true,
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                DatePattern  = "_yyyyMMdd-hh\".log\"",

                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            var traceAppender = new log4net.Appender.TraceAppender()
            {
                Layout = new log4net.Layout.PatternLayout("[%thread] %level %logger - %message [Extra Info: %property{testProperty} %exception]%n")
            };

            hierarchy.Root.AddAppender(rollingAppender);
            hierarchy.Root.AddAppender(traceAppender);
            rollingAppender.ActivateOptions();

            hierarchy.Root.Level = log4net.Core.Level.All;
        }
Ejemplo n.º 18
0
        public static void Init()
        {
            _AppDir = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Darel Dispatcher";

            if (!Directory.Exists(_AppDir))
            {
                Directory.CreateDirectory(_AppDir);
            }

            var logDir = _AppDir + "\\Logs";

            if (!Directory.Exists(logDir))
            {
                Directory.CreateDirectory(logDir);
            }

            //var filter = new log4net.Filter.LevelRangeFilter
            //{
            //    LevelMin = new log4net.Core.Level(1, "INFO"),
            //    LevelMax = new log4net.Core.Level(4, "FATAL"),
            //};

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.RemoveAllAppenders();

            var patternLayout = new PatternLayout
            {
                ConversionPattern = "%date [%level] %logger - %message%newline"
            };

            patternLayout.ActivateOptions();

            var appender = new log4net.Appender.RollingFileAppender
            {
                File               = logDir + "\\", //+ "\\log.txt",
                AppendToFile       = true,
                MaximumFileSize    = "5MB",
                MaxSizeRollBackups = 20,
                RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Composite,
                StaticLogFileName  = false,
                DatePattern        = "dd.MM.yyyy'.log'",
                Layout             = patternLayout
            };

            appender.ActivateOptions();

            hierarchy.Root.AddAppender(appender);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;

            Log = LogManager.GetLogger(
                System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

            //appender.AddFilter(filter);

            //log4net.Config.BasicConfigurator.Configure(appender);
        }
Ejemplo n.º 19
0
 // static constructor for log4net
 static PqsqlConnectionPool()
 {
     log4net.Layout.PatternLayout         layout   = new log4net.Layout.PatternLayout("%date{ISO8601} [%thread] %-5level %logger - %message%newline");
     log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender
     {
         File   = "c:\\windows\\temp\\pqsql_connection_pool.log",
         Layout = layout
     };
     layout.ActivateOptions();
     appender.ActivateOptions();
     log4net.Config.BasicConfigurator.Configure(appender);
     mLogger = log4net.LogManager.GetLogger(typeof(PqsqlConnectionPool));
 }
Ejemplo n.º 20
0
 static Logger()
 {
     var pattern = "%date %level - %message %exception%newline";
       var appender = new log4net.Appender.RollingFileAppender {
     Layout = new log4net.Layout.PatternLayout(pattern),
     File = "log.txt",
     AppendToFile = true,
     MaximumFileSize = "100KB",
     StaticLogFileName = true
       };
       appender.ActivateOptions();
       log4net.Config.BasicConfigurator.Configure(appender);
       log = LogManager.GetLogger("LoLGears");
 }
Ejemplo n.º 21
0
 void StartLogging()
 {
     //Setup log4net for the current domain
     log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
     log4net.Layout.PatternLayout         layout   = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");
     appender.Layout       = layout;
     appender.File         = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"log\servicebrowser.log");
     appender.AppendToFile = true;
     appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
     appender.DatePattern  = "yyyyMMdd";
     layout.ActivateOptions();
     appender.ActivateOptions();
     log4net.Config.BasicConfigurator.Configure(appender);
 }
Ejemplo n.º 22
0
Archivo: Log.cs Proyecto: 232629/test
        static Log()
        {
            logger = LogManager.GetLogger("MainLogger");

            log4net.Appender.RollingFileAppender logappender = new log4net.Appender.RollingFileAppender();
            logappender.File           = System.AppDomain.CurrentDomain.BaseDirectory + @"\logs\log.txt";
            logappender.AppendToFile   = true;
            logappender.ImmediateFlush = true;
            logappender.Layout         = new log4net.Layout.PatternLayout("%d [%-5p] - %m%n");
            logappender.LockingModel   = new log4net.Appender.FileAppender.MinimalLock();
            logappender.RollingStyle   = log4net.Appender.RollingFileAppender.RollingMode.Once;
            logappender.ActivateOptions();
            log4net.Config.BasicConfigurator.Configure(logappender);
        }
Ejemplo n.º 23
0
Archivo: Logger.cs Proyecto: zjbsean/TM
        /// <summary>
        /// 初始化日志
        /// </summary>
        /// <param name="file">日志文件</param>
        /// <param name="datePattern">日期格式</param>
        /// <param name="fileLevelStr">文件日志等级,有debug、info、warn、error和fatal</param>
        /// <param name="consoleLevelStr">Console日志等级</param>
        /// <returns>返回是否成功</returns>
        public bool Initialize(string file, string datePattern, string fileLevelStr, string consoleLevelStr)
        {
            log4net.Core.Level fileLevel    = ConvertLog4NetLevel(fileLevelStr);
            log4net.Core.Level consoleLevel = ConvertLog4NetLevel(consoleLevelStr);

            const string DefaultPattern = "%d [%t]%-5p %c - %m%n";

            try
            {
                log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(DefaultPattern);
                if (file != string.Empty)
                {
                    log4net.Appender.RollingFileAppender rfileAppender = new log4net.Appender.RollingFileAppender();
                    rfileAppender.Layout = layout;
                    rfileAppender.File   = file;

                    if (datePattern == string.Empty)
                    {
                        rfileAppender.DatePattern = "yyyyMMdd-HH";
                    }
                    else
                    {
                        rfileAppender.DatePattern = datePattern;
                    }
                    rfileAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date; //.Composite;
                    rfileAppender.Threshold    = fileLevel;
                    rfileAppender.ActivateOptions();
                    log4net.Config.BasicConfigurator.Configure(rfileAppender);
                }

                log4net.Appender.ConsoleAppender consoleAppender = new log4net.Appender.ConsoleAppender(layout);
                consoleAppender.Threshold = consoleLevel;
                consoleAppender.ActivateOptions();
                log4net.Config.BasicConfigurator.Configure(consoleAppender);
                return(true);
            }
            catch (Exception err)
            {
                Console.WriteLine("Error:{0} StackTrace:{1}", err.Message, err.StackTrace);
                try
                {
                    HTEventLog.InitFileLog(@"ServerEvents.log");
                    HTEventLog.SaveLog(HTEventLog.LogTypeEnum.错误, string.Format("Error : {0}\r\nStackTrace : \r\n{1}", err.Message, err.StackTrace), System.Windows.Forms.Application.ProductName);
                }
                catch
                {
                }
                return(false);
            }
        }
Ejemplo n.º 24
0
        public static void ActivateOptionsMSS(
            log4net.Appender.RollingFileAppender target)
        {
            object result;

            if (TestSpecificStubsUtil.RunTestSpecificStub(System.Reflection.MethodBase.GetCurrentMethod(), new object[] { target }, out result))
            {
                return;
            }
            else
            {
                target.ActivateOptions();
            }
        }
Ejemplo n.º 25
0
        public static void Configure()
        {
            if (isConfigured)
                return;

            var loggerName = "SBDIL";

            var logger = (log4net.Repository.Hierarchy.Logger)log4net.LogManager.GetRepository().GetLogger(loggerName);
            var ilogger = log4net.LogManager.GetRepository().GetLogger(loggerName);

            //Add the default log appender if none exist
            if(logger.Appenders.Count == 0)
            {
                var directoryName = "C:\\BarkLogs";

                //If the directory doesn't exist then create it
                if(!Directory.Exists(directoryName))
                    Directory.CreateDirectory(directoryName);

                var fileName = Path.Combine(directoryName, DateTime.Now.ToString("yyyyMMddTHHmmss") + ".txt");

                //Create the rolling file appender
                var appender = new log4net.Appender.RollingFileAppender();
                appender.Name = "RollingFileAppender";
                appender.File = fileName;
                appender.StaticLogFileName = true;
                appender.AppendToFile = false;
                appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;
                appender.MaxSizeRollBackups = 10;
                appender.MaximumFileSize = "10MB";
                appender.PreserveLogFileNameExtension = true;

                //Configure the layout of the trace message write
                var layout = new log4net.Layout.PatternLayout()
                {
                    ConversionPattern = "%date{MM/dd/yyyy hh:mm:ss.fff} - %message%newline"
                };
                appender.Layout = layout;
                layout.ActivateOptions();

                //Let log4net configure itself based on the values provided
                appender.ActivateOptions();
                log4net.Config.BasicConfigurator.Configure(appender);
            }

            iLog = LogManager.GetLogger(loggerName);
            isConfigured = true;
        }
Ejemplo n.º 26
0
        public static void Configure(out string v_config_file)
        {
            v_config_file = AppDomain.CurrentDomain.BaseDirectory + "MailGO.dll.config";
            log4net.Config.XmlConfigurator.Configure(new FileInfo(v_config_file));

            log4net.Appender.IAppender[] t_appender_list = log4net.LogManager.GetRepository().GetAppenders();
            foreach (log4net.Appender.IAppender t_appender in t_appender_list)
            {
                if (t_appender.GetType().ToString().Equals("log4net.Appender.RollingFileAppender"))
                {
                    log4net.Appender.RollingFileAppender t_file_appender = t_appender as log4net.Appender.RollingFileAppender;
                    t_file_appender.File = Path.Combine(Path.GetDirectoryName(v_config_file), Path.GetFileName(t_file_appender.File));
                    t_file_appender.ActivateOptions();
                }
            }
        }
Ejemplo n.º 27
0
 static Logger()
 {
     var pattern = "%date %level - %message %exception";
       var appender = new log4net.Appender.RollingFileAppender {
     Layout = new log4net.Layout.PatternLayout(pattern),
     File = Util.PathCombine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SciGit", "error.log"),
     AppendToFile = true,
     RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Composite,
     MaxSizeRollBackups = 1,
     MaximumFileSize = "1MB",
     StaticLogFileName = true
       };
       appender.ActivateOptions();
       log4net.Config.BasicConfigurator.Configure(appender);
       log = LogManager.GetLogger("SciGit");
 }
Ejemplo n.º 28
0
        public static void Configure()
        {
            string t_config_file = Assembly.GetExecutingAssembly().Location + ".config";

            log4net.Config.XmlConfigurator.Configure(new FileInfo(t_config_file));

            log4net.Appender.IAppender[] t_appender_list = log4net.LogManager.GetRepository().GetAppenders();
            foreach (log4net.Appender.IAppender t_appender in t_appender_list)
            {
                if (t_appender.GetType().ToString().Equals("log4net.Appender.RollingFileAppender"))
                {
                    log4net.Appender.RollingFileAppender t_file_appender = t_appender as log4net.Appender.RollingFileAppender;
                    t_file_appender.File = Path.Combine(Path.GetDirectoryName(t_config_file), Path.GetFileName(t_file_appender.File));
                    t_file_appender.ActivateOptions();
                }
            }
        }
Ejemplo n.º 29
0
        static void CreateAppender(AppenderConfiguration configuration, log4net.Core.IAppenderAttachable collection)
        {
            if (configuration != null)
            {
                if (!string.IsNullOrEmpty(configuration.Name))
                {
                    if (collection.GetAppender(configuration.Name) == null)
                    {
                        // Create the appender and add it to the loggers collection of appenders.
                        // Create the appender based on the type of configuration.
                        if (configuration is RollingFileAppenderConfiguration)
                        {
                            var rolling_file_configuration = configuration as RollingFileAppenderConfiguration;

                            // If a file name is not provided for the log file then attempt to use the applications name.
                            var rolling_appender = new log4net.Appender.RollingFileAppender
                            {
                                Name = configuration.Name,
                                MaxSizeRollBackups = Convert.ToInt32(rolling_file_configuration.MaxArchivedFiles),
                                MaximumFileSize    = rolling_file_configuration.RollSizeKB,
                                RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size,
                                StaticLogFileName  = true,
                                LockingModel       = new log4net.Appender.RollingFileAppender.MinimalLock(),
                                File = rolling_file_configuration.Path + (string.IsNullOrEmpty(rolling_file_configuration.FileName) ? GetApplicationName() + ".log" : rolling_file_configuration.FileName),
                                PreserveLogFileNameExtension = true,
                                Layout = new log4net.Layout.PatternLayout(rolling_file_configuration.Template),
                            };

                            //rolling_appender.AddFilter(new log4net.Filter.PropertyFilter{ Key="", StringToMatch=""}); //.StringMatchFilter { StringToMatch = category });
                            //rolling_appender.AddFilter(new log4net.Filter.DenyAllFilter());
                            rolling_appender.ActivateOptions();

                            collection.AddAppender(rolling_appender);
                        }
                        else
                        {
                            throw new Exception("Unable to create the appender. " + configuration.GetType().Name + "'s are not supported.");
                        }
                    }
                }
                else
                {
                    throw new Exception("Unable to create the appender. The name property is undefined.");
                }
            }
        }
Ejemplo n.º 30
0
        private void WriteLogger(string logType, string fileName, StringBuilder msgSB)
        {
            ILog   logger    = log4net.LogManager.GetLogger(_repository.Name, "MyLog");
            string logHeader = "== {0} ====================== " + DateTime.Now + Environment.NewLine;

            _rollingFileAppender.File         = string.Format(fileName, logType);
            _rollingFileAppender.AppendToFile = true;
            logHeader      = string.Format(logHeader, logType);
            _layout.Header = logHeader;
            _rollingFileAppender.Layout = _layout;
            //如果设置Appender使用了静态文件名,那么历史日志会被覆盖
            ///_rollingFileAppender.StaticLogFileName = false;
            _rollingFileAppender.ActivateOptions();
            _repository.Threshold = log4net.Core.Level.Info;
            log4net.Config.BasicConfigurator.Configure(_repository, _rollingFileAppender);
            logger.Info(msgSB.ToString().TrimEnd(new char[] { '\r', '\n' }));
        }
Ejemplo n.º 31
0
        /// <summary>
        /// This method is used to create the appender
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="appenderName"></param>
        /// <returns></returns>
        private log4net.Appender.FileAppender CreateAppender(string fileName, string appenderName)
        {
            //log4net.Appender.FileAppender fileAppender = new log4net.Appender.FileAppender();
            log4net.Appender.RollingFileAppender fileAppender = new log4net.Appender.RollingFileAppender();

            log4net.Layout.PatternLayout patternLayOut = new log4net.Layout.PatternLayout();
            patternLayOut.Header            = ""; //System.Environment.NewLine + "---Starts Here---" + System.Environment.NewLine;
            patternLayOut.Footer            = ""; //
            patternLayOut.ConversionPattern = "%d %m%n";

            //patternLayOut.ConversionPattern = "";
            patternLayOut.ActivateOptions();


            string path = AppDomain.CurrentDomain.BaseDirectory + @"\Log"; //System.Windows.Forms.Application.StartupPath + @"\Log";

            System.IO.DirectoryInfo info = new DirectoryInfo(path);

            if (!info.Exists)
            {
                info.Create();
            }
            string[] file = fileName.Split('\\');


            fileAppender.Layout = patternLayOut;


            fileAppender.AppendToFile    = true;
            fileAppender.MaximumFileSize = Parameter.LOGGING_FILE_SIZE.Trim().Equals("") ? DefaultMaximumFileSize : Parameter.LOGGING_FILE_SIZE;

            fileAppender.MaxSizeRollBackups = 10;
            fileAppender.StaticLogFileName  = true;
            fileAppender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size;

            //fileAppender.DatePattern = ".yyyyMMdd'.log'";
            //fileAppender.File = path + "\\" + file[file.Length - 1].Split('.')[0];

            fileAppender.File = path + "\\" + file[file.Length - 1];
            fileAppender.Name = appenderName;

            fileAppender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
            fileAppender.ActivateOptions();

            return(fileAppender);
        }
Ejemplo n.º 32
0
        private static log4net.Appender.FileAppender GetSpringFileAppender(
            string filelogPath, log4net.Core.Level fileLogLevel)
        {
            log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
            appender.Name               = "SpringLog";
            appender.AppendToFile       = true;
            appender.File               = filelogPath + "\\Spring.log";
            appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size;
            appender.MaxSizeRollBackups = 10;
            appender.MaximumFileSize    = "10MB";
            appender.StaticLogFileName  = true;
            appender.Layout             = new log4net.Layout.PatternLayout(
                "%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n");
            appender.Threshold = fileLogLevel;
            appender.ActivateOptions();

            return(appender);
        }
 /// <summary>
 /// Creates the log.
 /// </summary>
 /// <param name="cfg">The CFG.</param>
 /// <returns></returns>
 private ILog createLogger(log4net.Core.Level logLevel)
 {
     log4net.Appender.RollingFileAppender rollingFileAppender = new log4net.Appender.RollingFileAppender();
     rollingFileAppender.Name               = "API";
     rollingFileAppender.AppendToFile       = true;
     rollingFileAppender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Size;
     rollingFileAppender.MaximumFileSize    = "500KB";
     rollingFileAppender.MaxSizeRollBackups = 100;
     rollingFileAppender.StaticLogFileName  = true;
     rollingFileAppender.File               = "Logs\\API.log";
     rollingFileAppender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();
     rollingFileAppender.Layout             = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");
     rollingFileAppender.ImmediateFlush     = true;
     rollingFileAppender.Threshold          = logLevel;
     rollingFileAppender.ActivateOptions();
     log4net.Config.BasicConfigurator.Configure(rollingFileAppender);
     return(log4net.LogManager.GetLogger("API"));
 }
Ejemplo n.º 34
0
 private void ConfigureLog4Net(log4net.Core.Level LogLevel = null)
 {
     if (Equals(LogLevel, null))
     {
         LogLevel = log4net.Core.Level.All;
     }
     log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
     appender.Layout             = new log4net.Layout.SimpleLayout();
     appender.File               = CORE.LOG_FILE_PATH;
     appender.AppendToFile       = true;
     appender.ImmediateFlush     = true;
     appender.Threshold          = LogLevel;
     appender.MaxSizeRollBackups = 3;
     appender.MaximumFileSize    = "128KB";
     appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Once;
     appender.ActivateOptions();
     log4net.Config.BasicConfigurator.Configure(appender);
 }
 //TODO: move this in to the config file
 private ILog createLogger(log4net.Core.Level logLevel)
 {
     log4net.Appender.RollingFileAppender rollingFileAppender = new log4net.Appender.RollingFileAppender();
     rollingFileAppender.Name = "Client";
     rollingFileAppender.AppendToFile = true;
     rollingFileAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;
     rollingFileAppender.MaximumFileSize = "500KB";
     rollingFileAppender.MaxSizeRollBackups = 100;
     rollingFileAppender.StaticLogFileName = true;
     rollingFileAppender.File = "Logs\\Client.log";
     rollingFileAppender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
     rollingFileAppender.Layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");
     rollingFileAppender.ImmediateFlush = true;
     rollingFileAppender.Threshold = logLevel;
     rollingFileAppender.ActivateOptions();
     log4net.Config.BasicConfigurator.Configure(rollingFileAppender);
     return log4net.LogManager.GetLogger("Client");
 }
Ejemplo n.º 36
0
        static Log()
        {
            var appender = new log4net.Appender.RollingFileAppender();

            appender.File               = _filePath;
            appender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();
            appender.Layout             = new log4net.Layout.PatternLayout(_patternLayout);
            appender.MaxSizeRollBackups = -1;
            appender.RollingStyle       = log4net.Appender.RollingFileAppender.RollingMode.Date;
            appender.DatePattern        = _datePattern;
            appender.StaticLogFileName  = false;
            appender.LockingModel       = new log4net.Appender.FileAppender.MinimalLock();
            appender.ActivateOptions();
            appender.Encoding          = Encoding.Default;
            appender.StaticLogFileName = false;
            appender.AppendToFile      = true;
            appender.Name = _logKey;
            log4net.Config.BasicConfigurator.Configure(appender);
        }
Ejemplo n.º 37
0
        private static void ReconfigLogAppender(string _configFile, string refixLogName)
        {
            FileInfo fInfo = new FileInfo(_configFile);

            log4net.Config.XmlConfigurator.ConfigureAndWatch(fInfo);
            string appenderNames = "FileAppender";

            log4net.Appender.IAppender[] appenders = logger.Logger.Repository.GetAppenders();
            foreach (log4net.Appender.IAppender appender in appenders)
            {
                if (appenderNames.Equals(appender.Name))
                {
                    log4net.Appender.RollingFileAppender fileAppender = appender as log4net.Appender.RollingFileAppender;
                    fileAppender.File = Path.Combine(Path.GetDirectoryName(fileAppender.File), refixLogName + Path.GetExtension(fileAppender.File));
                    fileAppender.ActivateOptions();
                    break;
                }
            }
        }
        internal TsdQueryLogSink(string filename, string datePattern, int maxRollBackups, bool immediateFlush, JSONLogFormat.IJsonLogSerializer serializer)
        {
            Logger = Common.Logging.LogManager.GetLogger(typeof(TsdQueryLogSink));
            var reposName = Guid.NewGuid().ToString();

            var repos = LogManager.CreateRepository(reposName);
            var appender = new log4net.Appender.RollingFileAppender();
            //appender.MaxFileSize = maxFileSize;
            appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
            appender.MaxSizeRollBackups = maxRollBackups;
            appender.File = filename;
            appender.Layout = new log4net.Layout.PatternLayout("%message%newline");
            appender.ImmediateFlush = immediateFlush;
            appender.StaticLogFileName = false;
            appender.DatePattern = datePattern;
            appender.ActivateOptions();
            log4net.Config.BasicConfigurator.Configure(repos, appender);
            SampleLogger = LogManager.GetLogger(reposName, "SampleLogger");

            Serializer = serializer;
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Static constructor which init the logger object
        /// </summary>
        static Log()
        {
            log4net.Appender.RollingFileAppender oRollingFileAppender = new log4net.Appender.RollingFileAppender()
            {
                AppendToFile = true,
                File = "Logs/log.txt",
                Layout = new log4net.Layout.PatternLayout("[%date{ISO8601}] [%level] %message%newline"),
                LockingModel = new log4net.Appender.RollingFileAppender.MinimalLock(),
                MaximumFileSize = "10MB",
                MaxSizeRollBackups = 20,
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size,
            };

            oRollingFileAppender.ActivateOptions();

            log4net.Repository.ILoggerRepository oRepository = log4net.LogManager.GetRepository();
            log4net.Core.Level oInfoLevel = oRepository.LevelMap["All"];
            oRepository.LevelMap.Add(oInfoLevel.Name, oInfoLevel.Value);

            log4net.Config.BasicConfigurator.Configure(oRepository, oRollingFileAppender);
            _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        }
Ejemplo n.º 40
0
        public static void InitializeLog4Net()
        {
            var layout = new log4net.Layout.PatternLayout()
                {
                    ConversionPattern = "时间:%d %n级别:%level %n类名:%c%n文件:%F 第%L行%n日志内容:%m%n-----------------------------------------%n%n"
                };
            var appender = new log4net.Appender.RollingFileAppender()
            {
                AppendToFile = true,
                LockingModel = new log4net.Appender.FileAppender.MinimalLock(),
                StaticLogFileName = false,
                File = System.Configuration.ConfigurationManager.AppSettings["LogFolder"] + "log_PingAn_",
                RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date,
                DatePattern = "yyyy-MM-dd\".log\"",
                Layout = layout

            };
            layout.ActivateOptions();
            appender.ActivateOptions();
            log4net.Config.BasicConfigurator.Configure(appender);

            //log4net.Config.XmlConfigurator.Configure();
        }
Ejemplo n.º 41
0
        private static log4net.Appender.FileAppender GetSpringFileAppender(
            string filelogPath, log4net.Core.Level fileLogLevel)
        {
            log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
            appender.Name = "SpringLog";
            appender.AppendToFile = true;
            appender.File = filelogPath + "\\Spring.log";
            appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;
            appender.MaxSizeRollBackups = 10;
            appender.MaximumFileSize = "10MB";
            appender.StaticLogFileName = true;
            appender.Layout = new log4net.Layout.PatternLayout(
                "%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c - %m%n");
            appender.Threshold = fileLogLevel;
            appender.ActivateOptions();

            return appender;
        }
        /// <summary>
        /// Creates a file appender for FTP transaction logging
        /// </summary>
        /// <param name="logFileName">Log file name for the appender to use</param>
        /// <returns>A configured file appender</returns>
        private static log4net.Appender.RollingFileAppender CreateFtpLogfileAppender(string logFileName)
        {
            var ReturnAppender = new log4net.Appender.RollingFileAppender();

                ReturnAppender.Name = "RollingFileAppender";
                //m_FileDate = DateTime.Now.ToString("MM-dd-yyyy");
                //m_BaseFileName = logFileName;
                ReturnAppender.File = "FTPLog_";
                ReturnAppender.AppendToFile = true;
                ReturnAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
                ReturnAppender.DatePattern = "yyyyMMdd";
                var Layout = new log4net.Layout.PatternLayout();
                Layout.ConversionPattern = "%message%newline";
                Layout.ActivateOptions();
                ReturnAppender.Layout = Layout;
                ReturnAppender.ActivateOptions();

                return ReturnAppender;
        }
Ejemplo n.º 43
0
        /// <summary>
        /// add rolling file appender
        /// </summary>
        /// <param name="filename"></param>
        /// <param name="patternStr"></param>
        public static void AddFileLogger(String filename, String patternStr)
        {
            if (!String.IsNullOrEmpty(filename))
            {
                if (String.IsNullOrEmpty(patternStr))
                    patternStr = "%message%newline";

                log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(patternStr);

                log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
                appender.Layout = layout;
                appender.File = filename;
                appender.DatePattern = "\"_\"yyyyMMdd\".txt\"";
                appender.StaticLogFileName = false;
                appender.ActivateOptions();

                m_Appenders.Add(appender);
            }
        }
Ejemplo n.º 44
0
        /// <summary>
        /// intialize file writer
        /// </summary>
        /// <param name="_Filename"></param>
        void InitializeBackupFile(String _Filename)
        {
            try
            {
                if (!String.IsNullOrEmpty(_Filename) && null == m_BackupAppender)
                {
                    String patternStr = "%date : %message%newline";

                    log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout(patternStr);

                    log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
                    appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
                    appender.Layout = layout;
                    appender.File = _Filename;
                    appender.DatePattern = "\"_\"yyyyMMdd\".txt\"";
                    appender.StaticLogFileName = false;
                    appender.ActivateOptions();

                    m_BackupAppender = appender;
                }
            }
            catch (System.Exception ex)
            {
                m_BackupAppender = null;
                Log.Error("初始化备份文件失败.", ex);
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// This method is used to create the appender
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="appenderName"></param>
        /// <returns></returns>
        private log4net.Appender.FileAppender CreateAppender(string fileName, string appenderName)
        {
            //log4net.Appender.FileAppender fileAppender = new log4net.Appender.FileAppender();
            log4net.Appender.RollingFileAppender fileAppender = new log4net.Appender.RollingFileAppender();

            log4net.Layout.PatternLayout patternLayOut = new log4net.Layout.PatternLayout();
            patternLayOut.Header = ""; //System.Environment.NewLine + "---Starts Here---" + System.Environment.NewLine;
            patternLayOut.Footer = ""; //
            patternLayOut.ConversionPattern = "%d %m%n";

            //patternLayOut.ConversionPattern = "";
            patternLayOut.ActivateOptions();

            string path = AppDomain.CurrentDomain.BaseDirectory + @"\Log" ;
            System.IO.DirectoryInfo info = new DirectoryInfo(path);

            if (!info.Exists)
            {
                info.Create();
            }
            string[] file = fileName.Split('\\');

            fileAppender.Layout = patternLayOut;

            fileAppender.AppendToFile = true;
            fileAppender.MaximumFileSize = Parameter.LOGGING_FILE_SIZE.Trim().Equals("") ? DefaultMaximumFileSize : Parameter.LOGGING_FILE_SIZE;

            fileAppender.MaxSizeRollBackups = 10;
            fileAppender.StaticLogFileName = true;
            fileAppender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Size;

            //fileAppender.File = path + "\\" + file[file.Length - 1];
            fileAppender.File = path + "\\" + fileName;
            fileAppender.Name = appenderName;

            fileAppender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
            fileAppender.ActivateOptions();

            return fileAppender;
        }
        /// <summary>
        /// Configures the logger using the log4net library functions
        /// </summary>
        void ConfigureLogManager()
        {
            Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository();
            Logger rootLogger = hierarchy.Root;

            Logger coreLogger = hierarchy.GetLogger("KIKSoftwareProject.SkeletalDataProcessor") as Logger;
            coreLogger.Parent = rootLogger;

            log4net.Appender.RollingFileAppender fileAppender = new log4net.Appender.RollingFileAppender();
            fileAppender.File = "skeletalDP_Logs.txt";
            fileAppender.AppendToFile = true;
            fileAppender.MaximumFileSize = "100MB";
            fileAppender.MaxSizeRollBackups = 5;
            fileAppender.Layout = new log4net.Layout.PatternLayout(@"%date [%thread] %-5level %logger - %message%newline");
            fileAppender.StaticLogFileName = true;
            fileAppender.ActivateOptions();

            coreLogger.RemoveAllAppenders();
            coreLogger.AddAppender(fileAppender);
            hierarchy.Configured = true;

            skeletalDataLogger = LogManager.GetLogger("KIKSoftwareProject.SkeletalDataProcessor");
        }
Ejemplo n.º 47
0
        /// <summary>
        /// Configure log4net object
        /// </summary>
        private static void ConfigLog4Net()
        {
            // set log filename
            string logfilename = Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            logfilename += System.IO.Path.DirectorySeparatorChar;
            logfilename += System.Reflection.Assembly.GetExecutingAssembly().GetName().Name + ".log";

            LogFilePath = logfilename;

            // attach to repository hierarchy
            log4net.Repository.Hierarchy.Hierarchy repository = LogManager.GetRepository() as log4net.Repository.Hierarchy.Hierarchy;

            // check for logging into file
            if (LogToFile)
            {
                // add log file appender
                log4net.Appender.RollingFileAppender fileappender = new log4net.Appender.RollingFileAppender();
                fileappender.Layout = new log4net.Layout.PatternLayout("%-5level %date{yyyy-MM-dd HH:mm:ss,fff} [%thread] %message (%file:%line)%newline");
                fileappender.File = logfilename;
                fileappender.MaxSizeRollBackups = 10;
                fileappender.MaximumFileSize = "10MB";
                fileappender.AppendToFile = true;
                fileappender.ActivateOptions();
                repository.Root.AddAppender(fileappender);
            }

            // check for logging into console
            if (LogToConsole)
            {
                // add console appender
                log4net.Appender.ConsoleAppender consoleappender = new log4net.Appender.ConsoleAppender();
                consoleappender.Layout = new log4net.Layout.PatternLayout("%-5level %date{HH:mm:ss} %message%newline");
                consoleappender.ActivateOptions();
                repository.Root.AddAppender(consoleappender);
            }

            // set to log all events
            repository.Root.Level = log4net.Core.Level.All;
            repository.Configured = true;
            repository.RaiseConfigurationChanged(EventArgs.Empty);
        }
Ejemplo n.º 48
0
		void StartLogging()
		{
			//Setup log4net for the current domain
			log4net.Appender.RollingFileAppender appender = new log4net.Appender.RollingFileAppender();
			log4net.Layout.PatternLayout layout = new log4net.Layout.PatternLayout("%date [%thread] %-5level %logger - %message%newline");
			appender.Layout = layout;
			appender.File = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"log\servicebrowser.log");
			appender.AppendToFile = true;
			appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
			appender.DatePattern = "yyyyMMdd";
			layout.ActivateOptions();
			appender.ActivateOptions();
			log4net.Config.BasicConfigurator.Configure(appender);
		}
        /// <summary>
        /// Configure the log manager
        /// </summary>
        void ConfigureLogManager()
        {
            Hierarchy hierarchy = (Hierarchy)log4net.LogManager.GetRepository();
            Logger rootLogger = hierarchy.Root;

            Logger coreLogger = hierarchy.GetLogger("KIKSoftwareProject.SkeletonTransformation") as Logger;
            coreLogger.Parent = rootLogger;

            log4net.Appender.RollingFileAppender fileAppender = new log4net.Appender.RollingFileAppender();
            fileAppender.File = "Transformation_log.txt";
            fileAppender.AppendToFile = true;
            fileAppender.MaximumFileSize = "100MB";
            fileAppender.MaxSizeRollBackups = 5;
            fileAppender.Layout = new log4net.Layout.PatternLayout(@"%date [%thread] %-5level %logger - %message%newline");
            fileAppender.StaticLogFileName = true;
            fileAppender.ActivateOptions();

            coreLogger.RemoveAllAppenders();
            coreLogger.AddAppender(fileAppender);
            hierarchy.Configured = true;

            kinectEventLogger = LogManager.GetLogger("KIKSoftwareProject.SkeletonTransformation");

            log4net.LogManager.GetRepository().Threshold = log4net.Core.Level.Debug;
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Initialisiert das Logging und die Debug TextBox
        /// </summary>
        private void InitLog()
        {
            #region RichTextBoxAppender
            RichTextBoxAppender rba = new RichTextBoxAppender(rtbDebug);
            rba.Threshold = Level.All;
            rba.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss.fff} %5level %message %n");

            LevelTextStyle ilts = new LevelTextStyle();
            ilts.Level = Level.Info;
            ilts.TextColor = Color.DarkBlue;
            ilts.PointSize = 8.0f;
            rba.AddMapping(ilts);

            LevelTextStyle dlts = new LevelTextStyle();
            dlts.Level = Level.Debug;
            dlts.TextColor = Color.DeepSkyBlue;
            dlts.PointSize = 8.0f;
            rba.AddMapping(dlts);

            LevelTextStyle wlts = new LevelTextStyle();
            wlts.Level = Level.Warn;
            wlts.TextColor = Color.Gold;
            wlts.PointSize = 8.0f;
            rba.AddMapping(wlts);

            LevelTextStyle elts = new LevelTextStyle();
            elts.Level = Level.Error;
            elts.TextColor = Color.Crimson;
            elts.BackColor = Color.Cornsilk;
            elts.PointSize = 8.0f;
            rba.AddMapping(elts);

            LevelTextStyle flts = new LevelTextStyle();
            flts.Level = Level.Fatal;
            flts.TextColor = Color.White;
            flts.BackColor = Color.Red;
            flts.PointSize = 8.0f;
            rba.AddMapping(flts);

            log4net.Config.BasicConfigurator.Configure(rba);
            rba.ActivateOptions();
            #endregion RichTextBoxAppender

            #region RollingFileAppender
            log4net.Appender.RollingFileAppender fa = new log4net.Appender.RollingFileAppender();
            fa.AppendToFile = true;
            fa.Threshold = log4net.Core.Level.All;
            fa.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Date;
            fa.MaxFileSize = 100000;
            fa.MaxSizeRollBackups = 10;
            fa.File = @".\LogPath\K-S2-Remote_";
            fa.DatePattern = @"yyyyMMdd.lo\g";
            fa.StaticLogFileName = false;

            // fa.Layout = new log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss.fff} %5level %message (%logger{1}:%line)%n");
            log4net.Layout.PatternLayout pl = new log4net.Layout.PatternLayout(
                "%date [%thread] %-5level %message    (%logger)%newline");
            pl.Header = "######### K-S2-Remote_ gestartet ############\n";
            pl.Footer = "######### K-S2-Remote_ gestoppt  ############\n";
            fa.Layout = pl;

            log4net.Config.BasicConfigurator.Configure(fa);
            fa.ActivateOptions();
            #endregion RollingFileAppender
        }