Beispiel #1
0
        public logRecord(string _name, loggerLevels _level, string _msg, object[] _args, string _exc_info = null, [CallerMemberName] string _func = "", [CallerFilePath] string _pathname = "", [CallerLineNumber] long _lineno = 0)
        {
            attributes = new Dictionary <string, object>();
            name       = _name;

            levelName = _level.ToString();
            levelNo   = (int)_level;
            levelEnum = _level;

            created = DateTime.Now;
            msecs   = created.Millisecond;

            Process tempProcess = Process.GetCurrentProcess();

            processName = tempProcess.ProcessName;
            process     = tempProcess.Id;

            this._msg = _msg;

            args = _args;

            funcName = _func;
            pathname = _pathname;
            lineno   = _lineno;
        }
Beispiel #2
0
 public override bool log(string message_in, loggerLevels level_in)
 {
     if (this.getlevel() <= level_in)
     {
         this.logAction(message_in);
         return(true);
     }
     return(false);
 }
        public void formatter_properlyAddsLoggerName()
        {
            string testMessage = "testLogger {0}, {1}";

            string[]     argsArray  = new string[] { "test_args1", "test_args2" };
            loggerLevels testLevel  = loggerLevels.CRITICAL;
            string       loggerName = "formatter Test";

            formatter b = new formatter("{levelName}:{name}:{message}");
            logRecord l = new logRecord(loggerName, testLevel, testMessage, argsArray, "");

            string resultMessage = String.Format("{0}:{1}:{2}", testLevel, loggerName, String.Format(testMessage, argsArray));

            Console.WriteLine(b.format(l));
            Assert.AreEqual(resultMessage, b.format(l));
        }
Beispiel #4
0
        private void executeLog(loggerLevels methodLevel, string message_in, object[] args, string _func, string _pathname, long _lineno)
        {
            if (!string.IsNullOrWhiteSpace(_message_template))
            {
                string conformedMessage_template = _message_template;
                if (conformedMessage_template.Contains("{message}"))
                {
                    conformedMessage_template = conformedMessage_template.Replace("{message}", "{0}");
                }

                if (!conformedMessage_template.Contains("{0}"))
                {
                    conformedMessage_template = $"{conformedMessage_template} {{0}}";
                }

                message_in = string.Format(conformedMessage_template, message_in);
            }
            logRecord record = new logRecord(_name, methodLevel, message_in, args, null, _func, _pathname, _lineno);

            handle(record);
        }
 public abstract bool log(string message_in, loggerLevels level_in);
 public void setLevel(loggerLevels level_in)
 {
     this.loggerLevel = level_in;
 }
Beispiel #7
0
 public bool isEnabledFor(loggerLevels level_in)
 {
     return(level_in >= this.getlevel());
 }