Esempio n. 1
0
        internal void InternalLog(string logLevel, string content, string scope = "")
        {
            var _scope    = string.IsNullOrWhiteSpace(scope) ? Scope : scope;
            var _logLevel = string.IsNullOrWhiteSpace(logLevel) ? null : LogLevels.FirstOrDefault(n => n.Name.ToLower() == logLevel.ToLower());

            var builder = new StringBuilder();

            if (TimeStamps)
            {
                builder.Append($"{DateTime.Now.ToString(TimeStampsFormat).Pastel(_logLevel.Color)} ");
            }

            if (!string.IsNullOrWhiteSpace(_scope))
            {
                builder.Append($"[{_scope}]".Pastel(Colors[0]) + " ");
            }

            if (_logLevel != null)
            {
                builder.Append($"{ _logLevel.Icon.Pastel(_logLevel.Color) } { Ansi.Underline(_logLevel.Name).Pastel(_logLevel.Color).Expand(BiggestLength) } ");
            }
            else
            {
                builder.Append("".Expand(BiggestLength + 3));
            }

            builder.Append(content.Pastel(Colors[1]));

            var message = builder.ToString();

            foreach (var output in Outputs)
            {
                output.WriteLine(message);
            }
        }
Esempio n. 2
0
        protected virtual string FormatLog(string logLevel, string content, string scope = "")
        {
            var _scope    = string.IsNullOrWhiteSpace(scope) ? Scope : scope;
            var _logLevel = string.IsNullOrWhiteSpace(logLevel) ? null : LogLevels.FirstOrDefault(n => String.Equals(n.Name, logLevel, StringComparison.CurrentCultureIgnoreCase));

            var builder = new StringBuilder();

            if (TimeStamps)
            {
                builder.Append($"{DateTime.Now.ToString(TimeStampFormat).Pastel(_logLevel.Color)} ");
            }

            if (!string.IsNullOrWhiteSpace(_scope))
            {
                builder.Append($"[{_scope}]".Pastel(Colors[0]) + " ");
            }

            if (_logLevel != null)
            {
                builder.Append($"{ _logLevel.Icon.Pastel(_logLevel.Color) } { Ansi.Underline(_logLevel.Name).Pastel(_logLevel.Color).Expand(BiggestLength) } ");
            }
            else
            {
                builder.Append("".Expand(BiggestLength + 3));
            }

            builder.Append(content.Pastel(Colors[1]));

            return(builder.ToString());
        }