Beispiel #1
0
 public Task Log(object message, SimpleLogLevel level)
 {
     if (this.ShouldLog(level))
     {
         var args = LogMessageArgs.Create(Category, message, level);
         LogActions.Invoke(args);
     }
     return(Task.CompletedTask);
 }
Beispiel #2
0
        public Task Log(object message, SimpleLogLevel level)
        {
            if (level >= EnabledLevel)
            {
                LogMessage(message, level);
            }

            return(Task.FromResult(0));
        }
Beispiel #3
0
        public static SimpleLogTestHelper Create(string fooCategory, SimpleLogLevel fooLevel, SimpleLogLevel defaultLevel)
        {
            var simpleLogTestHelper = new SimpleLogTestHelper();

            simpleLogTestHelper.FooCategory  = fooCategory;
            simpleLogTestHelper.FooLevel     = fooLevel;
            simpleLogTestHelper.DefaultLevel = defaultLevel;
            return(simpleLogTestHelper);
        }
Beispiel #4
0
        public void SetEnabledLevel(string category, SimpleLogLevel level)
        {
            if (string.IsNullOrWhiteSpace(category))
            {
                throw new ArgumentNullException(nameof(category));
            }

            var key         = category.Trim();
            var tryGetValue = Items.TryGetValue(key, out var setting);

            if (!tryGetValue || setting == null)
            {
                setting          = new SimpleLogSetting();
                setting.Category = key;
            }
            setting.EnabledLevel = level;
        }
Beispiel #5
0
        /// <summary>
        /// Log text
        /// </summary>
        /// <param name="level">Log level</param>
        /// <param name="text">Text to log</param>
        public static void Log(SimpleLogLevel level, string text)
        {
            lock (_lock)
            {
                LogWriter.Write(DateTime.Now.ToUniversalTime().ToString("[yyyyMMddHHmmss] ", CultureInfo.InvariantCulture.DateTimeFormat));
                LogWriter.Write("#{0:x8} ", System.Threading.Thread.CurrentThread.ManagedThreadId);
                switch (level)
                {
                case SimpleLogLevel.Checkpoint:
                    LogWriter.Write("CHECK: ");
                    break;

                case SimpleLogLevel.Info:
                    LogWriter.Write("INFO:  ");
                    break;

                case SimpleLogLevel.Warn:
                    LogWriter.Write("WARN:  ");
                    break;

                case SimpleLogLevel.Error:
                    LogWriter.Write("ERROR: ");
                    break;
                }
                bool isFirst = true;
                foreach (var line in text.Split('\n'))
                {
                    if (isFirst)
                    {
                        LogWriter.WriteLine(line);
                        isFirst = false;
                    }
                    else
                    {
                        LogWriter.WriteLine("                                  " + line);
                    }
                }
                LogWriter.Flush();
            }
        }
Beispiel #6
0
 public static bool ShouldLog(this ISimpleLog simpleLog, SimpleLogLevel currentLevel)
 {
     return(currentLevel.ShouldLog(simpleLog.EnabledLevel));
 }
Beispiel #7
0
 public static bool ShouldLog(this SimpleLogLevel currentLevel, SimpleLogLevel enabledLevel)
 {
     return(currentLevel >= enabledLevel && currentLevel != SimpleLogLevel.None);
 }
Beispiel #8
0
 public static LogMessageArgs Create(string category, object message, SimpleLogLevel level)
 {
     return(new LogMessageArgs(category, message, level));
 }
Beispiel #9
0
 public LogMessageArgs(string category, object message, SimpleLogLevel level)
 {
     Category = category;
     Message  = message;
     Level    = level;
 }
Beispiel #10
0
 /// <summary>
 /// Log text
 /// </summary>
 /// <param name="level">Log level</param>
 /// <param name="text">Text to log</param>
 /// <param name="args">Format arguments</param>
 public static void Log(SimpleLogLevel level, string text, params object[] args)
 {
     Log(level, String.Format(text, args));
 }
Beispiel #11
0
 protected virtual void LogMessage(object message, SimpleLogLevel level)
 {
     Trace.WriteLine(string.Format("{0} [{1}][{2}] {3}", Category, "SimpleLog", level.ToString(), message));
 }
Beispiel #12
0
 public SimpleLogger(SimpleLogLevel logLevel)
 {
     _logLevel = logLevel;
 }