public static int Priority(this SmartLogLevel smartLogLevel)
        {
            int index    = Index(smartLogLevel);
            int priority = (int)SmartLogLevelValues.GetValue(index);

            return(priority);
        }
        public void Log <T>(SmartLogLevel smartLogLevel,
                            string line)
        {
            SmartLogLine smartLogLine = smartLogLevel.CreateSmartLogLine <T>(line);

            Enqueue(smartLogLine);
        }
        private static int Index(this SmartLogLevel smartLogLevel)
        {
            // ReSharper disable once HeapView.BoxingAllocation
            int indexOf = Array.IndexOf(SmartLogLevelValues,
                                        smartLogLevel);

            return(indexOf);
        }
        public static SmartLogLine CreateSmartLogLine <T>(this SmartLogLevel smartLogLevel,
                                                          string line)
        {
            SmartLogLine smartLogLine = SmartLogLine.Create(typeof(T),
                                                            smartLogLevel,
                                                            line);

            return(smartLogLine);
        }
        public void Log(SmartLogLevel smartLogLevel,
                        string line)
        {
            SmartLogLines smartLogLines = GetOrAdd(smartLogLevel,
                                                   new SmartLogLines());

            smartLogLines.Log <T>(smartLogLevel,
                                  line);
        }
        public static string ToLine(this SmartLogLevel smartLogLevel)
        {
            string name = Enum.GetName(typeof(SmartLogLevel),
                                       // ReSharper disable once HeapView.BoxingAllocation
                                       smartLogLevel);
            int    priority = smartLogLevel.Priority();
            string line     = $"{priority.ToString()}-{name}";

            return(line);
        }
        public static SmartLogPerTypeByLevel <T> Log <T>(this SmartLoggerPerType <T> smartLoggerPerType,
                                                         SmartLogLevel smartLogLevel,
                                                         string line)
        {
            SmartLogPerTypeByLevel <T> smartLogPerTypeByLevel = smartLoggerPerType.GetOrAdd(typeof(T),
                                                                                            new SmartLogPerTypeByLevel <T>());

            smartLogPerTypeByLevel.Log(smartLogLevel,
                                       line);
            return(smartLogPerTypeByLevel);
        }
Exemple #8
0
        public static SmartLogLine Create(Type type,
                                          SmartLogLevel smartLogLevel,
                                          string line)
        {
            // ReSharper disable once HeapView.ObjectAllocation.Evident
            SmartLogLine smartLogLine = new SmartLogLine(type,
                                                         smartLogLevel,
                                                         line);

            return(smartLogLine);
        }
Exemple #9
0
 // ReSharper disable once MemberCanBePrivate.Global
 public SmartLogLine(Type type,
                     SmartLogLevel smartLogLevel,
                     string line)
 {
     At          = DateTime.UtcNow;
     MachineName = Environment.MachineName;
     ThreadName  = Thread.CurrentThread.Name;
     Type        = type;
     Level       = smartLogLevel;
     Line        = line;
 }
        public static SmartLogPerTypeByLevel <T> Log <T>(this SmartLoggerPerType <T> smartLoggerPerType,
                                                         string action,
                                                         SmartLogLevel smartLogLevel,
                                                         string message)
        {
            string line = SmartLogLine.GetLine(action,
                                               smartLogLevel.ToLine(),
                                               message);
            SmartLogPerTypeByLevel <T> smartLogPerTypeByLevel = smartLoggerPerType.Log(smartLogLevel,
                                                                                       line);

            return(smartLogPerTypeByLevel);
        }
        private SmartLogPerTypeByLevel <SmartLoggerTests> AssertGetSmartLog(string action,
                                                                            SmartLogLevel smartLogLevel,
                                                                            SmartLogPerTypeByLevel <SmartLoggerTests> expectedSmartLogPerTypeByLevel)
        {
            Assert.NotNull(expectedSmartLogPerTypeByLevel);
            SmartLogPerTypeByLevel <SmartLoggerTests> smartLogPerTypeByLevel = SmartLoggerPerType.Log(action,
                                                                                                      smartLogLevel,
                                                                                                      SmartLogGeneratorName);

            Assert.NotNull(smartLogPerTypeByLevel);
            Assert.AreEqual(expectedSmartLogPerTypeByLevel,
                            smartLogPerTypeByLevel);
            LogSize(smartLogLevel);
            return(smartLogPerTypeByLevel);
        }
        private void AssertGetSmartLog(SmartLogLevel smartLogLevel,
                                       SmartLogLevel logLevel)
        {
            SmartLoggerPerType.TryGetValue(typeof(SmartLoggerTests),
                                           out SmartLogPerTypeByLevel <SmartLoggerTests> expectedSmartLogPerTypeByLevel);
            SmartLogPerTypeByLevel <SmartLoggerTests> smartLogPerTypeByLevel = AssertGetSmartLog(Getting,
                                                                                                 smartLogLevel,
                                                                                                 expectedSmartLogPerTypeByLevel);

            Thread.Sleep(100);
            LogSize(smartLogLevel);
            string line = SmartLogLine.GetLine(logLevel.ToLine(),
                                               SmartLogGeneratorName,
                                               smartLogLevel.ToLine());

            smartLogPerTypeByLevel.Log(logLevel,
                                       line);
            Thread.Sleep(100);
        }
        private void LogSize(SmartLogLevel smartLogLevel)
        {
            SmartLoggerPerType.TryGetValue(typeof(SmartLoggerTests),
                                           out SmartLogPerTypeByLevel <SmartLoggerTests> smartLogPerTypeByLevel);
            Assert.NotNull(smartLogPerTypeByLevel);

            smartLogPerTypeByLevel.TryGetValue(smartLogLevel,
                                               out SmartLogLines smartLogLines);
            Assert.NotNull(smartLogLines);

            string line = SmartLogLine.GetLine(SmartLogGeneratorName,
                                               Size,
                                               smartLogPerTypeByLevel.Size().ToString());

            smartLogPerTypeByLevel.Log(smartLogLevel,
                                       line);
            Assert.IsNotEmpty(smartLogLines);
            Thread.Sleep(100);
        }