Example #1
0
        public void ConfigureLogging()
        {
            var tracer    = new TraceAppender();
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            hierarchy.Root.AddAppender(tracer);

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

            patternLayout.ActivateOptions();
            tracer.Layout = patternLayout;

            var fileAppender = new FileAppender
            {
                AppendToFile = true,
                File         = LogFile,
                Layout       = patternLayout,
                LockingModel = new FileAppender.ExclusiveLock()
            };

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

            hierarchy.Root.Level = hierarchy.LevelMap[LogLevel];
            hierarchy.Configured = true;
        }
Example #2
0
        /// <summary>
        /// 取得Log4j实例
        /// </summary>
        /// <param name="settingName">配置名称</param>
        /// <param name="logfileName">WXMessageBox文件名</param>
        /// <returns>Log4j实例</returns>
        protected static ILog GetLogger(string settingName, string logfileName)
        {
            //Log文件的路径
            string path = SystemFilePath.FilePathLoggingSetting;

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

            //Log文件名
            string logfilePath = SystemFilePath.DirLog + "\\" + logfileName + ".log";

            foreach (ILoggerRepository repository in log4net.LogManager.GetAllRepositories())
            {
                foreach (IAppender appender in repository.GetAppenders())
                {
                    if (appender.Name.IndexOf("_Template_") >= 0)
                    {
                        FileAppender fileAppender = appender as FileAppender;
                        if (fileAppender != null)
                        {
                            fileAppender.File         = logfilePath;
                            fileAppender.LockingModel = new log4net.Appender.FileAppender.MinimalLock();
                            fileAppender.ActivateOptions();
                        }
                    }
                }
            }
            ILog log = log4net.LogManager.GetLogger(settingName);

            return(log);
        }
Example #3
0
        private static void ConfigureAppenders()
        {
            var layout = new PatternLayout {
                ConversionPattern = "[%d{HH:mm:ss}] [%t/%level] [%logger]: %m%n"
            };

            layout.ActivateOptions();

            var appenders = new List <IAppender>();

#if CLIENT
            appenders.Add(new ConsoleAppender {
                Name   = "ConsoleAppender",
                Layout = layout
            });
#endif
            appenders.Add(new DebugAppender {
                Name   = "DebugAppender",
                Layout = layout
            });

            var fileAppender = new FileAppender {
                Name         = "FileAppender",
                File         = LogPath = Path.Combine(LogDir, GetNewLogFile(side)),
                AppendToFile = false,
                Encoding     = Encoding.UTF8,
                Layout       = layout
            };
            fileAppender.ActivateOptions();
            appenders.Add(fileAppender);

            BasicConfigurator.Configure(appenders.ToArray());
        }
Example #4
0
        /// <summary>
        /// 使用文本记录异常日志
        /// </summary>
        /// <Author>Ryanding</Author>
        /// <date>2011-05-01</date>
        public static void LoadFileAppender()
        {
            string currentPath = AppDomain.CurrentDomain.BaseDirectory;
            string txtLogPath  = string.Empty;
            string iisBinPath  = AppDomain.CurrentDomain.RelativeSearchPath;

            if (!string.IsNullOrEmpty(iisBinPath))
            {
                txtLogPath = CreateDirectory(iisBinPath);// Path.Combine(iisBinPath, "ErrorLog.txt");
            }
            else
            {
                txtLogPath = CreateDirectory(currentPath);// Path.Combine(currentPath, "ErrorLog.txt");
            }
            log4net.Repository.Hierarchy.Hierarchy hier =
                log4net.LogManager.GetLoggerRepository() as log4net.Repository.Hierarchy.Hierarchy;

            FileAppender fileAppender = new FileAppender();

            fileAppender.Name         = "LogFileAppender";
            fileAppender.File         = txtLogPath;
            fileAppender.AppendToFile = true;

            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = "记录时间:%date LOG描述:%message%newline";
            patternLayout.ActivateOptions();
            fileAppender.Layout = patternLayout;

            //选择UTF8编码,确保中文不乱码。
            fileAppender.Encoding = Encoding.UTF8;

            fileAppender.ActivateOptions();
            BasicConfigurator.Configure(fileAppender);
        }
Example #5
0
        /// <summary>
        /// Configures the <see cref="FileLogger"/> logger adding the appenders to
        /// the root repository.
        /// </summary>
        /// <remarks></remarks>
        public void Configure()
        {
            // create a new logger into the repository of the current assembly.
            ILoggerRepository root_repository =
                LogManager.GetRepository(Assembly.GetExecutingAssembly());

            Logger nohros_file_logger =
                root_repository.GetLogger("NohrosFileAppender") as Logger;

            // create the layout and appender for log messages
            PatternLayout layout = new PatternLayout();

            layout.ConversionPattern = layout_pattern_;
            layout.ActivateOptions();

            FileAppender appender = new FileAppender();

            appender.Name         = "NohrosCommonFileAppender";
            appender.File         = log_file_path_;
            appender.AppendToFile = true;
            appender.Layout       = layout;
            appender.Threshold    = Level.All;
            appender.ActivateOptions();

            // add the appender to the root repository
            nohros_file_logger.Parent.AddAppender(appender);

            root_repository.Configured = true;

            logger = LogManager.GetLogger("NohrosFileLogger");
        }
Example #6
0
        public CustomLogger(string path, string prefix, Level minLevel, Level maxLevel)
        {
            this.string_0 = prefix;
            this.level_0  = minLevel ?? Level.All;
            this.level_1  = maxLevel ?? Level.Emergency;
            Directory.CreateDirectory(path);
            PatternLayout layout = new PatternLayout("%-4utcdate [%thread] %-5level %logger{1} %ndc - %message%newline");
            DateTime      now    = DateTime.Now;

            object[] args = new object[] { now.Year, now.Month, now.Day, now.Hour, now.Minute, Process.GetCurrentProcess().Id, path, this.string_0 };
            this.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), string.Format(@"{6}\{7} {5} {0:0000}-{1:00}-{2:00} {3:00}.{4:00}.txt", args));
            FileAppender newAppender = new FileAppender {
                File         = this.FileName,
                Layout       = layout,
                LockingModel = new FileAppender.MinimalLock()
            };
            LevelRangeFilter filter = new LevelRangeFilter {
                LevelMin      = this.level_0,
                LevelMax      = this.level_1,
                AcceptOnMatch = true
            };

            newAppender.AddFilter(filter);
            layout.ActivateOptions();
            newAppender.ActivateOptions();
            AsyncAppender appender2 = new AsyncAppender();

            appender2.AddAppender(newAppender);
            appender2.ActivateOptions();
            log4net.Repository.Hierarchy.Hierarchy hierarchy1 = (log4net.Repository.Hierarchy.Hierarchy)LogManager.CreateRepository(this.string_0);
            hierarchy1.Root.AddAppender(appender2);
            hierarchy1.Configured = true;
        }
Example #7
0
        public static void LoadFileAppender(ILoggerRepository repository, string logPath, Level level)
        {
            var patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = LOG_PATTERN;
            patternLayout.ActivateOptions();

            var fileAppender = new FileAppender();

            fileAppender.Threshold    = level;
            fileAppender.Name         = "FileAppender";
            fileAppender.File         = logPath;
            fileAppender.AppendToFile = false;
            fileAppender.Encoding     = Encoding.UTF8;
            fileAppender.Layout       = patternLayout;
            fileAppender.ActivateOptions();

            if (repository != null)
            {
                BasicConfigurator.Configure(repository, fileAppender);
            }
            else
            {
                BasicConfigurator.Configure(fileAppender);
            }
        }
Example #8
0
        static Logger()
        {
            Hierarchy     hierarchy     = (Hierarchy)LogManager.GetRepository();
            TraceAppender tracer        = new TraceAppender();
            PatternLayout patternLayout = new PatternLayout();

            patternLayout.ConversionPattern = LOG_PATTERN;
            patternLayout.ActivateOptions();

            tracer.Layout = patternLayout;
            tracer.ActivateOptions();
            tracer.Name = "tracer1";

            hierarchy.Root.AddAppender(tracer);

            FileAppender roller = new FileAppender();

            roller.Layout       = patternLayout;
            roller.AppendToFile = false;
            roller.File         = "dnservices1.txt";
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            hierarchy.Root.Level = Level.All;
            hierarchy.Configured = true;
        }
        private static void AddLog4NetConfig()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

            // defining the pattern layout
            var patternLayout = new PatternLayout();

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

            // creating the regular console appender
            var fileAppender = new FileAppender
            {
                Layout       = patternLayout,
                File         = "EJUPublisher.log",
                AppendToFile = true
            };

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

            // defining the level and finalizing the configuration
            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
Example #10
0
        private void SetupLog4Net()
        {
            // Uncomment the next line to enable log4net internal debugging
            // log4net.Util.LogLog.InternalDebugging = true;

            // This will instruct log4net to look for a configuration file
            // called config.log4net in the root directory of the device
            XmlConfigurator.Configure(new FileInfo(@"\logger.config"));

            repository = LogManager.CreateRepository("BoxLogRepository");

            // see: http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html
            ILayout layout = new PatternLayout("[%date{HH:mm:ss}] %-5level %message%newline");

            var fileAppender = new FileAppender();

            fileAppender.File         = filename;
            fileAppender.Layout       = layout;
            fileAppender.AppendToFile = false;
            fileAppender.ActivateOptions();

            var consoleAppender = new ConsoleAppender();

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

            BasicConfigurator.Configure(repository, fileAppender);
            BasicConfigurator.Configure(repository, consoleAppender);

            boxLog = LogManager.GetLogger(repository.Name, "BoxLog");

            repository.ConfigurationChanged += repository_ConfigurationChanged;
        }
Example #11
0
        private static void LoggingWithCodeConfiguration()
        {
            SimpleLayout layout = new SimpleLayout();

            layout.ActivateOptions();

            ConsoleAppender appender = new ConsoleAppender();

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

            FileAppender appender2 = new FileAppender();

            appender2.Layout = layout;
            appender2.File   = "FileLog2.txt";
            appender2.ActivateOptions();

            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();
            Logger    root      = hierarchy.Root;

            root.Level = Level.All;

            BasicConfigurator.Configure(new IAppender[] { appender, appender2 });

            ILog log = LogManager.GetLogger(typeof(Program));

            log.Debug("debug");
            log.Warn("warn");
            log.Error("");
            log.Fatal("fatality");
            log.Info("Hello from log4net!");

            Console.ReadLine();
        }
Example #12
0
        public static void Setup()
        {
            Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository();

            PatternLayout patternLayout = new PatternLayout();

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

            FileAppender roller = new FileAppender();

            roller.AppendToFile = true;
            var assemblyFolder = Helper.GetAssemblyFolder();

            roller.File   = Path.Combine(assemblyFolder, "#Test.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.Debug;
            hierarchy.Configured = true;
        }
Example #13
0
        public static void SetRunAppender()
        {
            if (!_alreadySetRunAppender)
            {
                _alreadySetRunAppender = true;

                var log = LogManager.GetLogger("dropkick");
                var l   = (log4net.Repository.Hierarchy.Logger)log.Logger;

                var layout = new PatternLayout
                {
                    ConversionPattern = "%message%newline"
                };
                layout.ActivateOptions();

                var app = new FileAppender
                {
                    Name         = "dropkick.run.log",
                    File         = string.Format("{0}.run.log", DateTime.Now.ToString("yyyyMMdd-HHmmssfff")),
                    Layout       = layout,
                    AppendToFile = false
                };
                app.ActivateOptions();

                l.AddAppender(app);
            }
        }
Example #14
0
        /// <summary>
        /// For engine use only! Not thread safe
        /// </summary>
        /// <param name="prefix"></param>
        public void SetLogFilePrefix(string prefix)
        {
            Info(typeof(Logger).Name, "SetLogFilePrefix", "Changing log file -> Adding prefix: '" + prefix + "'");
            try
            {
                log4net.Repository.Hierarchy.Hierarchy h =
                    (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
                foreach (IAppender a in h.Root.Appenders)
                {
                    if (a is FileAppender)
                    {
                        FileAppender fa = (FileAppender)a;

                        FileInfo fileInfo    = new FileInfo(fa.File);
                        var      logFileName = string.Format("{0}-{1}", prefix, fileInfo.Name);

                        fa.File = Path.Combine(fileInfo.DirectoryName, logFileName);
                        fa.ActivateOptions();
                        break;
                    }
                    else if (a is SmtpAppender)
                    {
                        SmtpAppender sa = (SmtpAppender)a;
                        sa.Subject = sa.Subject + " " + prefix;
                        sa.ActivateOptions();
                    }
                }
            }
            catch (Exception ex)
            {
                Error(typeof(Logger).Name, "SetLogFilePrefix", ex, "Prefix not set - log entries are probably in the base log file");
            }
        }
Example #15
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;
        }
Example #16
0
        // Create a new file appender
        public static void ConfigureLog4net(string name, string fileName)
        {
            PatternLayout layout = new PatternLayout("%date{yyyy-MM-dd HH:mm:ss,fff} %-5level [%thread]: %message%newline");

            layout.ActivateOptions();

            LevelMatchFilter filter = new LevelMatchFilter();

            filter.LevelToMatch = Level.All;
            filter.ActivateOptions();

            var appender = new FileAppender();

            appender.Name         = name;
            appender.File         = fileName;
            appender.AppendToFile = false;

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

            ILoggerRepository repository = LoggerManager.CreateRepository(name);

            BasicConfigurator.Configure(repository, appender);
        }
Example #17
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;
        }
Example #18
0
        /// <summary>
        /// Initializes the logging functionality.
        /// </summary>
        public static void Initialize()
        {
            var hierarchy = (Hierarchy)LogManager.GetRepository();

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

            patternLayout.ActivateOptions();

            var fileAppender = new FileAppender
            {
                AppendToFile = false,
                File         = Path.Combine(SettingsHelper.Instance.GetApplicationLocalUserSettingsDirectory(), "BOI", "Riskeer", "Riskeer-") + DateTime.Now.ToString("yyyy.MMM.dd.HH.mm.ss") + ".log",
                Layout       = patternLayout
            };

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

            var messageWindowLogAppender = new MessageWindowLogAppender();

            hierarchy.Root.AddAppender(messageWindowLogAppender);

            hierarchy.Root.Level = Level.Debug;
            hierarchy.Configured = true;
        }
Example #19
0
        public static void InitOutput(string name)
        {
            if (data == null)
            {
                data = new Dictionary <string, ILog>();
            }
            string fileName = String.Format("C:/naturTest/{0}_{1}.csv", name, DateTime.Now.ToString("dd_MM_yyyy_HH_mm"));

            try
            {
                if (!data.ContainsKey(name))
                {
                    LogManager.CreateRepository(name);
                    ILog logger = LogManager.GetLogger(name, name);
                    data.Add(name, logger);
                }

                FileAppender  appender = new FileAppender();
                PatternLayout layout   = new PatternLayout(@"%m%n");
                appender.Layout       = layout;
                appender.File         = fileName;
                appender.AppendToFile = true;
                BasicConfigurator.Configure(LogManager.GetRepository(name), appender);
                appender.ActivateOptions();
            }
            catch (Exception e)
            {
                Console.WriteLine("Ошибка при создании log-файла " + fileName);
                Console.WriteLine(e.Message);
            }
        }
Example #20
0
        private void SetupLog4Net()
        {
            var fileName = Path.Combine(Directory.GetCurrentDirectory(), @"..\Live\FileLogger.txt");

            Console.WriteLine("Logging to {0}", 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         = @"..\Live\FileLogger.txt",
                Layout       = patternLayout,
            };

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

            _hierarchy.Root.Level = Level.Debug;
            _hierarchy.Configured = true;
        }
Example #21
0
        public static bool ChangeLogFileLocation1(string NewFileName)
        {
            XmlConfigurator.Configure();
            log4net.Repository.Hierarchy.Hierarchy h =
                (log4net.Repository.Hierarchy.Hierarchy)LogManager.GetRepository();
            foreach (IAppender a in h.Root.Appenders)
            {
                if (a is FileAppender)
                {
                    FileAppender fa = (FileAppender)a;
                    // Programmatically set this to the desired location here
                    string logFileLocation = NewFileName;

                    // Uncomment the lines below if you want to retain the base file name
                    // and change the folder name...
                    //FileInfo fileInfo = new FileInfo(fa.File);
                    //logFileLocation = string.Format(@"C:\MySpecialFolder\{0}", fileInfo.Name);

                    fa.File = logFileLocation;
                    fa.ActivateOptions();
                    break;
                }
            }
            return(true);
        }
Example #22
0
        public RAMDatabase(bool useRAMOnly)
        {
            this.useRAMOnly = useRAMOnly;

            if (useRAMOnly)
            {
                pokerTables = new SortedDictionary <long, databaseCache.pokerTable>();
                localPokerTableIdToDatabaseTableId = new Dictionary <long, long>();
                pokerPlayers = new Dictionary <PokerClients, Dictionary <long, PokerPlayer> >();
                pokerHands   = new SortedDictionary <long, SortedDictionary <long, databaseCache.pokerHand> >();
                holeCards    = new Dictionary <long, Dictionary <long, databaseCache.holeCard> >();
                handActions  = new SortedDictionary <long, List <databaseCache.handAction> >();
            }

#if databaseLogging
            //If we are logging configure the logger
            ILoggerRepository            repository             = LogManager.GetRepository(Assembly.GetCallingAssembly());
            IBasicRepositoryConfigurator configurableRepository = repository as IBasicRepositoryConfigurator;

            PatternLayout layout = new PatternLayout();
            layout.ConversionPattern = "%level% [%thread%] - %message%newline";
            layout.ActivateOptions();

            FileAppender appender = new FileAppender();
            appender.Layout       = layout;
            appender.Threshold    = Level.Warn;
            appender.File         = "RAMDatabase.csv";
            appender.AppendToFile = true;
            appender.ActivateOptions();
            configurableRepository.Configure(appender);
#endif
        }
Example #23
0
        static LogManager()
        {
            var logFileName = "StudioShell." + Process.GetCurrentProcess().Id + ".log.txt";
            var profile     = new CodeOwls.StudioShell.Host.StudioShellProfileInfo();
            var logFilePath = Path.Combine(
                Path.GetDirectoryName(profile.CurrentUserCurrentHost),
                logFileName);


            var appender = new FileAppender();

            appender.AppendToFile   = false;
            appender.Encoding       = Encoding.ASCII;
            appender.ImmediateFlush = true;
            appender.LockingModel   = new FileAppender.ExclusiveLock();
            appender.Name           = "FileAppender1";
            appender.File           = logFilePath;
            appender.Layout         = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");
            appender.Threshold      = log4net.Core.Level.All;
            appender.ActivateOptions();

            log4net.Config.BasicConfigurator.Configure(appender);

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
        }
Example #24
0
        protected override void Initialize()
        {
            FileAppender fileAppender = new FileAppender();

            fileAppender.File         = "GameStatusLogs.txt";
            fileAppender.AppendToFile = true;
            fileAppender.Layout       = new log4net.Layout.SimpleLayout();
            fileAppender.Threshold    = Level.Info;
            fileAppender.ActivateOptions();

            BasicConfigurator.Configure(fileAppender);

            // Create a new SpriteBatch, which can be used to draw textures.
            SpriteBatch = new SpriteBatch(GraphicsDevice);
            // device = graphics.GraphicsDevice;

            ScreenWidth  = graphics.PreferredBackBufferWidth;
            ScreenHeight = graphics.PreferredBackBufferHeight;

            video       = Content.Load <Video>("media/IntroVideo");
            videoPlayer = new VideoPlayer();
            videoPlayer.Play(video);
            videoColor = new Color(255, 255, 255);

            base.Initialize();

            log.Info("XNA Game Initialization completed");
        }
        public static void InitializeLog()
        {
            log4net.Config.XmlConfigurator.Configure();
            var assemblyDir = Path.GetDirectoryName(
                new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase).LocalPath);

            //get the current logging repository for this application
            ILoggerRepository repository = LogManager.GetRepository();

            //get all of the appenders for the repository
            IAppender[] appenders = repository.GetAppenders();
            //only change the file path on the 'FileAppenders'
            foreach (IAppender appender in (from iAppender in appenders
                                            where iAppender is FileAppender
                                            select iAppender))
            {
                FileAppender fileAppender = appender as FileAppender;
                //set the path to your logDirectory using the original file name defined
                //in configuration
                var logFileName = $"{DateTime.Now.ToString("yyyy-MM-dd")}-{Path.GetFileName(fileAppender.File)}";
                fileAppender.File = Path.Combine(assemblyDir, $"..\\..\\..\\log\\{logFileName}");
                //make sure to call fileAppender.ActivateOptions() to notify the logging
                //sub system that the configuration for this appender has changed.
                fileAppender.ActivateOptions();
            }
        }
Example #26
0
        //static void InitXmlLog()
        //{
        //    XmlDocument log4netConfig = new XmlDocument();
        //    log4netConfig.LoadXml(@"
        //        <log4net>
        //          <appender name=""StringAppender"" type=""log4net.Tests.Appender.StringAppender, log4net.Tests"">
        //            <layout type=""log4net.Layout.SimpleLayout"" />
        //          </appender>
        //          <root>
        //            <level value=""ALL"" />
        //            <appender-ref ref=""StringAppender"" />
        //          </root>
        //          <logger name=""."">
        //            <level value=""WARN"" />
        //          </logger>
        //        </log4net>");

        //    ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
        //    XmlConfigurator.Configure(rep, log4netConfig["log4net"]);

        //    //CategoryTraceListener categoryTraceListener = new CategoryTraceListener();
        //    //Debug.Listeners.Add(categoryTraceListener);

        //    log = LogManager.GetLogger(rep.Name);
        //    log.Info("OPEN");
        //}
        static void InitLog()
        {
            ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());

            ////ConsoleAppender
            FileAppender fa = new FileAppender(new SimpleLayout(), "RoslynProj.log");

            fa.ActivateOptions();
            //  fa.ErrorHandler = new SilentErrorHandler();
            //DebugAppender fa = new DebugAppender();
            //fa.Layout = new SimpleLayout();
            //fa.ActivateOptions();
            //fa.Category = null;

            //TestErrorHandler testErrHandler = new TestErrorHandler();
            //debugAppender.ErrorHandler = testErrHandler;
            //ILog log = LogManager.GetLogger(rep.Name, GetType());
            BasicConfigurator.Configure(rep, fa);
            log = LogManager.GetLogger(rep.Name, "RoslynProj");
            log.Info("InitLog");

            //String filename = "test.log";
            //SilentErrorHandler sh = new SilentErrorHandler();
            //ILogger log = CreateLogger(filename, new FileAppender.ExclusiveLock(), sh);
            //log.Log(null, Level.Info, "This is a message", null);
            //log.Log(GetType(), Level.Info, "This is a message 2", null);
        }
Example #27
0
        public static void SetLogFileName(string logger, string logFileName)
        {
            bool found = false;

            Errors.Clear();
            var appenders = repo.GetAppenders();

            foreach (log4net.Appender.IAppender a in appenders)
            {
                if (a is FileAppender && a.Name == logger)
                {
                    FileAppender fa = (FileAppender)a;

                    fa.AppendToFile = false;
                    fa.File         = logFileName;
                    fa.ActivateOptions();
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                throw new Exception("Cannot find Appender " + logger);
            }
        }
Example #28
0
        static void ConfigureLogging(ServerOptions options)
        {
            var layout = new PatternLayout("%date %level - %message%newline");

            layout.ActivateOptions();

            var appenders = new List <IAppender>();

            if (!string.IsNullOrEmpty(options.LogFileDirectory))
            {
                var fileAppender = new FileAppender
                {
                    Layout         = layout,
                    Encoding       = Encoding.UTF8,
                    File           = Path.Combine(options.LogFileDirectory, "orchestrion.log"),
                    AppendToFile   = true,
                    LockingModel   = new FileAppender.MinimalLock(),
                    ImmediateFlush = true,
                };
                fileAppender.ActivateOptions();
                appenders.Add(fileAppender);
            }

            if (options.ConsoleOutput)
            {
                var consoleAppender = new ConsoleAppender
                {
                    Layout = layout
                };
                consoleAppender.ActivateOptions();
                appenders.Add(consoleAppender);
            }

            BasicConfigurator.Configure(appenders.ToArray());
        }
Example #29
0
        private static void InitLoggers(ServiceDescriptor d, bool enableCLILogging)
        {
            // TODO: Make logging levels configurable
            Level logLevel = Level.Debug;
            // TODO: Debug should not be printed to console by default. Otherwise commands like 'status' will be pollutted
            // This is a workaround till there is a better command line parsing, which will allow determining
            Level consoleLogLevel = Level.Info;
            Level eventLogLevel   = Level.Warn;

            // Legacy format from winsw-1.x: (DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " - " + message);
            PatternLayout pl = new PatternLayout {
                ConversionPattern = "%d %-5p - %m%n"
            };

            pl.ActivateOptions();

            List <IAppender> appenders = new List <IAppender>();

            // wrapper.log
            String wrapperLogPath = Path.Combine(d.LogDirectory, d.BaseName + ".wrapper.log");
            var    wrapperLog     = new FileAppender
            {
                AppendToFile   = true,
                File           = wrapperLogPath,
                ImmediateFlush = true,
                Name           = "Wrapper file log",
                Threshold      = logLevel,
                LockingModel   = new FileAppender.MinimalLock(),
                Layout         = pl
            };

            wrapperLog.ActivateOptions();
            appenders.Add(wrapperLog);

            // Also display logs in CLI if required
            if (enableCLILogging)
            {
                var consoleAppender = new ConsoleAppender
                {
                    Name      = "Wrapper console log",
                    Threshold = consoleLogLevel,
                    Layout    = pl,
                };
                consoleAppender.ActivateOptions();
                appenders.Add(consoleAppender);
            }

            // System log
            var systemEventLogger = new ServiceEventLogAppender
            {
                Name      = "System event log",
                Threshold = eventLogLevel,
                provider  = eventLogProvider
            };

            systemEventLogger.ActivateOptions();
            appenders.Add(systemEventLogger);

            BasicConfigurator.Configure(appenders.ToArray());
        }
        public static void ConfigureSimpleFileLogger(ThreadingType threadingType)
        {
            var logFileName = $"{Parameters.RootLogsDirectory}\\Log4Net.{threadingType}.SimpleFile.log";

            File.Delete(logFileName);

            PatternLayout patternLayout = new PatternLayout
            {
                ConversionPattern = LogOutputTemplate
            };

            patternLayout.ActivateOptions();

            var simpleFileAppender = new FileAppender
            {
                File   = logFileName,
                Layout = patternLayout
            };

            simpleFileAppender.ActivateOptions();
            Hierarchy.Root.AddAppender(simpleFileAppender);

            Hierarchy.Root.Level = Level.Info;

            Hierarchy.Configured = true;
        }