Exemplo n.º 1
0
        static Logger()
        {
            String    cur_dir   = System.IO.Directory.GetCurrentDirectory();
            Hierarchy hierarchy = (Hierarchy )LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = System.IO.Path.Combine(cur_dir, "TypeCobolBuilder.log");
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "1GB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 2
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %level (%file:%line) - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = @"R:\PROGETTI\DATA\DATA.log";
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "10MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
Exemplo n.º 3
0
        private static void SetupLogger()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

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

            patternLayout.ActivateOptions();
            var roller = new FileAppender
            {
                AppendToFile = false,
                File         = @"NUnit3AllureAdapter.log",
                Layout       = patternLayout
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 4
0
        private void SetupLog4Net()
        {
            // Replaces the configuration loaded from file
            //https://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file
            Hierarchy     hierarchy     = (Hierarchy)LogManager.GetRepository(Assembly.GetCallingAssembly());
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%message%newline";
            patternLayout.ActivateOptions();
            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile = true;
            // Use manual configuration because the %env for special folders no longer working
            roller.File =
                Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.None),
                    @"MultiCommDashboards\Logs\log.txt");
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "3GB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 5
0
        public Logger(string fileName)
        {
            _hierarchy = (Hierarchy)LogManager.GetRepository();

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

            patternLayout.ActivateOptions();

            var roller = new FileAppender
            {
                AppendToFile = true,
                File         = fileName,
                Layout       = patternLayout,
            };

            roller.ActivateOptions();
            _hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();

            memory.ActivateOptions();
            _hierarchy.Root.AddAppender(memory);

            _hierarchy.Root.Level = Level.Info;
            _hierarchy.Configured = true;
        }
Exemplo n.º 6
0
        static Logger()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level- %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile      = false;
            roller.File              = @"Logs\EngineLog.txt";
            roller.Layout            = patternLayout;
            roller.RollingStyle      = RollingFileAppender.RollingMode.Date;
            roller.StaticLogFileName = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 7
0
        /// <summary>
        /// call this to direct logging to an array in memory - useful in performace tests where we may wish
        /// to parse the log for timing info
        /// code fragment from http://dhvik.blogspot.com/2008/08/adding-appender-to-log4net-in-runtime.html
        /// </summary>
        static public void AddMemoryAppender()
        {
            //First create and configure the appender
            MemoryAppender memoryAppender = new MemoryAppender {
                Name = "MemoryAppender"
            };                                                                            // Not L10N

            //Notify the appender on the configuration changes
            memoryAppender.ActivateOptions();

            //Get the logger repository hierarchy.
            Hierarchy repository = LogManager.GetRepository() as Hierarchy;

            if (repository != null)
            {
                //and add the appender to the root level
                //of the logging hierarchy
                repository.Root.AddAppender(memoryAppender);

                //configure the logging at the root.
                repository.Root.Level = Level.All;

                //mark repository as configured and
                //notify that is has changed.
                repository.Configured = true;
                repository.RaiseConfigurationChanged(EventArgs.Empty);
            }
        }
    public ILog Setup(string logFilePath, string logName, string maxFileSize = "10MB")
    {
        var patternLayout = new PatternLayout();

        patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
        patternLayout.ActivateOptions();
        var roller = new RollingFileAppender();

        roller.AppendToFile       = true;
        roller.File               = logFilePath;
        roller.Layout             = patternLayout;
        roller.MaxSizeRollBackups = 5;
        roller.MaximumFileSize    = maxFileSize;
        roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
        roller.StaticLogFileName  = true;
        roller.ActivateOptions();
        //hierarchy.Root.AddAppender(roller);
        var memory = new MemoryAppender();

        memory.ActivateOptions();
        ILog log = LogManager.GetLogger(logName);
        var  l   = (Logger)log.Logger;

        l.AddAppender(roller);
        l.AddAppender(memory);
        l.Level = l.Hierarchy.LevelMap["Debug"];
        l.Repository.Configured = true;
        return(log);
    }
Exemplo n.º 9
0
        public static void SetupLog()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = Application.UserAppDataPath + "\\ZonBarcodeLog.txt";
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "10MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

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

            _ServiceLog = LogManager.GetLogger("ServiceLog");
        }
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout
            {
                ConversionPattern = "%date{dd-MMM-yyyy HH:mm:ss} %level %message%newline"
            };

            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender
            {
                AppendToFile = true,
                File         = @"..\..\LoggFiles\\" +
                               DateTime.Now.ToString("dd-MMM-yyyy") /*+ "\\" + DateTime.Now.ToString("hh.mm.ss") */ + ".txt",
                Layout             = patternLayout,
                MaxSizeRollBackups = 5,
                MaximumFileSize    = "1GB",
                RollingStyle       = RollingFileAppender.RollingMode.Size,
                StaticLogFileName  = true
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 11
0
        public static void ConfigureLog4NetForSetup()
        {
            String path = @"C:\Users\Public\Documents\OctaneTfsPlugin\logs\setup.log";

            Directory.CreateDirectory(Path.GetDirectoryName(path));

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

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = path;
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 2;
            roller.MaximumFileSize    = "3MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            roller.LockingModel = new FileAppender.MinimalLock();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
Exemplo n.º 12
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date %-5level - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = @"logs\";
            roller.DatePattern        = "yyyy.MM.dd'.log'";
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 30;
            roller.MaximumFileSize    = "5MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Composite;
            roller.StaticLogFileName  = false;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
        public override void Configure(Assembly sourceAssembly, ILoggerRepository targetRepository)
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = ConfigurationManager.AppSettings["LogFileLocation"];
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "1GB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 14
0
        public static void Configure()
        {
            if (isSetupLogHandler)
            {
                return;
            }
            isSetupLogHandler = true;

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

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = Environment.ExpandEnvironmentVariables(@"%AppData%\MyGitHubProject\UseRegistryInWPF\UseRegistryInWPFLog.txt");
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 20;
            roller.MaximumFileSize    = "20MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 15
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout()
            {
                ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"
            };

            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender {
                AppendToFile = true, StaticLogFileName = true, File = @"Logs\Log.log", Layout = patternLayout, MaxSizeRollBackups = 5, MaximumFileSize = "5MB", RollingStyle = RollingFileAppender.RollingMode.Size
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            BasicConfigurator.Configure(hierarchy);
            hierarchy.Configured = true;
        }
Exemplo n.º 16
0
        private LogHelper()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            var patternLayout = new PatternLayout
            {
                ConversionPattern = LogPatternLayout
            };

            patternLayout.ActivateOptions();

            var roller = new RollingFileAppender
            {
                AppendToFile       = true,
                File               = $@"RunLog\\{Path.GetFileNameWithoutExtension(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path))}.log",
                Layout             = patternLayout,
                MaxSizeRollBackups = 300,
                MaximumFileSize    = "1MB",
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                StaticLogFileName  = true,
                DatePattern        = "_yyyy-MM-dd'.log'"
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
            InternalLogger       = LogManager.GetLogger("");
        }
Exemplo n.º 17
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date{dd/MM/yyyy hh:mm:ss.fff tt} | %logger[%method:%line] %level - %message%newline%exception";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.Encoding           = Encoding.UTF8;
            roller.File               = Path.Combine(AddonEx.dir_Logs, "AddonManager.log");
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "5MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

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

            doFirstEntry();
        }
Exemplo n.º 18
0
        public FileLogger(LoggingLevel loggingLevel = LoggingLevel.Information)
        {
            LoggingLevel = loggingLevel;
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile = false;
            roller.File         = @"logs\trademeup.log";
            roller.DatePattern  = "yyyy-MM-dd";
            roller.Layout       = patternLayout;
            roller.PreserveLogFileNameExtension = true;
            roller.MaxSizeRollBackups           = 5;
            roller.MaximumFileSize   = "1GB";
            roller.RollingStyle      = RollingFileAppender.RollingMode.Date;
            roller.StaticLogFileName = false;
            roller.ActivateOptions();

            hierarchy.Root.AddAppender(roller);

            MemoryAppender memoryAppender = new MemoryAppender();

            memoryAppender.ActivateOptions();
            hierarchy.Root.AddAppender(memoryAppender);

            hierarchy.Configured = true;
        }
Exemplo n.º 19
0
            public static void SetupLogger(String path)
            {
                Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

                if (hierarchy.Configured)
                {
                    return;
                }

                PatternLayout patternLayout = new PatternLayout();

                patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
                patternLayout.ActivateOptions();

                RollingFileAppender roller = new RollingFileAppender();

                roller.AppendToFile       = true;
                roller.File               = Path.Combine(path);
                roller.Layout             = patternLayout;
                roller.MaxSizeRollBackups = 5;
                roller.MaximumFileSize    = "10MB";
                roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
                roller.StaticLogFileName  = true;
                roller.LockingModel       = new FileAppender.MinimalLock();
                roller.ActivateOptions();
                hierarchy.Root.AddAppender(roller);

                MemoryAppender memory = new MemoryAppender();

                memory.ActivateOptions();
                hierarchy.Root.AddAppender(memory);

                hierarchy.Root.Level = Level.Info;
                hierarchy.Configured = true;
            }
        public void TestThreadSafety()
        {
            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
            var memoryAppender    = new MemoryAppender();
            var patternLayout     = new PatternLayout();

            memoryAppender.Layout = patternLayout;
            memoryAppender.ActivateOptions();
            BasicConfigurator.Configure(rep, memoryAppender);

            cThreadsRunning = cThreadsMax;
            var threads = Enumerable.Range(0, cThreadsMax)
                          .Select(i => new Thread(LogMessages(rep.Name)))
                          .ToList();

            foreach (var thread in threads)
            {
                thread.Start();
            }

            long cEventsRead = 0;

            while (cThreadsRunning > 0)
            {
                var events = memoryAppender.PopAllEvents();
                cEventsRead += events.Length;
            }
            foreach (var thread in threads)
            {
                thread.Join();
            }
            cEventsRead += memoryAppender.PopAllEvents().Length;
            Assert.AreEqual(cEventsExpected, cEventsRead, "Log events were lost.");
        }
Exemplo n.º 21
0
        /// <summary>
        /// Sets up a new logging instance
        /// </summary>
        public static void Setup(string logName)
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

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

            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender
            {
                AppendToFile       = true,
                File               = Core.Common.GetLogFolderPath() + "\\" + logName + ".txt",
                Layout             = patternLayout,
                MaxSizeRollBackups = 5,
                MaximumFileSize    = "1GB",
                RollingStyle       = RollingFileAppender.RollingMode.Size,
                StaticLogFileName  = true
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
        public static void SetupLog4Net(string path)
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = path;
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "1GB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

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

            Logger = LogManager.GetLogger(typeof(DebugHelper));
        }
Exemplo n.º 23
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "xltrail", "logs", "xltrail-addin.log");
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "1048576";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 24
0
        private static void SetupLog4Net()
        {
            var hierarchy = (Hierarchy)log4net.LogManager.GetRepository(Assembly.GetAssembly(typeof(Log4NetLoggingTests)));

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

            patternLayout.ActivateOptions();

            //RollingFileAppender roller = new RollingFileAppender();
            //roller.AppendToFile = false;
            //roller.File = @"Logs\EventLog.txt";
            //roller.Layout = patternLayout;
            //roller.MaxSizeRollBackups = 5;
            //roller.MaximumFileSize = "1GB";
            //roller.RollingStyle = RollingFileAppender.RollingMode.Size;
            //roller.StaticLogFileName = true;
            //roller.ActivateOptions();
            //hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
Exemplo n.º 25
0
        public static void LoggerSetup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = ConstUtil.LogConversionPattern;
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.File               = ConstUtil.LogPath;
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = ConstUtil.MaxSizeRollBackup;
            roller.MaximumFileSize    = ConstUtil.MaxLogSize;
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;
        }
Exemplo n.º 26
0
        public Log4NetHelper()
        {
            Hierarchy     hierarchy     = (Hierarchy)LogManager.GetRepository();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = true;
            roller.File               = @"Logs\EventLog.txt";
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "1GB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
        public static void DebugConfig()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.RemoveAllAppenders();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date|||[%thread]|||%-5level|||%property{method_name}|||%property{type}|||%property{model}|||%message%newline";
            patternLayout.ActivateOptions();
            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile                 = true;
            roller.LockingModel                 = new FileAppender.MinimalLock();
            roller.File                         = @"logs\";
            roller.Layout                       = patternLayout;
            roller.MaxSizeRollBackups           = 5;
            roller.MaximumFileSize              = "2048KB";
            roller.DatePattern                  = "dd.MM.yyyy'.log'";
            roller.RollingStyle                 = RollingFileAppender.RollingMode.Composite;
            roller.StaticLogFileName            = false;
            roller.PreserveLogFileNameExtension = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);
            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);
            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Setups the logger configuration. Can be used instead of loading log4net.config file
        /// </summary>
        public static void SetupLogger()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new DynamicPatternLayout();

            patternLayout.ConversionPattern = "%date{dd MMM yyyy HH:mm:ss} [%thread] %level   -   %message %exception %newline";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender
            {
                // appends the log into same file
                AppendToFile       = true,
                File               = @"DeployLogs\\Deploylog.log",
                Layout             = patternLayout,
                MaxSizeRollBackups = 1000,
                RollingStyle       = RollingFileAppender.RollingMode.Date,
                StaticLogFileName  = false
            };

            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memoryAppender = new MemoryAppender();

            memoryAppender.ActivateOptions();

            hierarchy.Root.AddAppender(memoryAppender);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
Exemplo n.º 29
0
        static void Main(string[] args)
        {
            var logger = LogManager.GetLogger(typeof(Program));

            LogicalThreadContext.Stacks["activity"].Push("First Activity");
            LogicalThreadContext.Stacks["activity"].Push("Second Activity");
            logger.Info("File Appender with JSON formatter");

            //add a memory appender so we don't seem crazy.
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.RemoveAllAppenders();
            var layout = new JsonLayout();

            layout.ActivateOptions();
            var memoryAppender = new MemoryAppender {
                Layout = layout
            };

            memoryAppender.ActivateOptions();
            hierarchy.Root.AddAppender(memoryAppender);
            hierarchy.Configured = true;
            logger.Info("Memory Appender with JSON Formatter");

            //have to get it out of the memoryappendor to trigger the code.
            memoryAppender.Layout.Format(Console.Out, memoryAppender.GetEvents()[0]);
        }
Exemplo n.º 30
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "%date{dd/MM/yyyy hh:mm:ss.fff tt} | %logger[%method:%line] %level - %message%newline%exception";
            patternLayout.ActivateOptions();

            RollingFileAppender roller = new RollingFileAppender();

            roller.AppendToFile       = false;
            roller.Encoding           = Encoding.UTF8;
            roller.File               = DataEx.log_Events;
            roller.Layout             = patternLayout;
            roller.MaxSizeRollBackups = 5;
            roller.MaximumFileSize    = "5MB";
            roller.RollingStyle       = RollingFileAppender.RollingMode.Size;
            roller.StaticLogFileName  = true;
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            MemoryAppender memory = new MemoryAppender();

            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = (bool)App.Current.Properties["Troubleshooting"] ? Level.Debug : Level.Info;
            hierarchy.Configured = true;

            doFirstEntry();
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates the memory logger.
        /// </summary>
        private static MemoryAppender CreateMemoryLogger()
        {
            var hierarchy = (Hierarchy) LogManager.GetRepository();

            var memory = new MemoryAppender();
            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

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

            return memory;
        }