示例#1
0
        public static async Task LogAsync(string source, LogSeverity severity, string message, Exception exception = null)
        {
            if (severity.Equals(null))
            {
                severity = LogSeverity.Warning;
            }

            await Append($"{GetSeverityString(severity)}", GetConsoleColor(severity));
            await Append($" [{SourceToString(source)}] ", ConsoleColor.DarkGray);

            if (!string.IsNullOrWhiteSpace(message))
            {
                await Append($"{message}\n", ConsoleColor.White);
            }
            else if (exception == null)
            {
                await Append("Uknown Exception. Exception Returned Null.\n", ConsoleColor.DarkRed);
            }
            else if (exception.Message == null)
            {
                await Append($"Unknownk \n{exception.StackTrace}\n", GetConsoleColor(severity));
            }
            else
            {
                await Append($"{exception.Message ?? "Unknownk"}\n{exception.StackTrace ?? "Unknown"}\n", GetConsoleColor(severity));
            }
        }
示例#2
0
        public static async Task LogAsync(string src, LogSeverity severity, string message, Exception exception = null)
        {
            if (severity.Equals(null))
            {
                severity = LogSeverity.Warning;
            }

            await Log($" {System.DateTime.Now} ", ConsoleColor.DarkBlue);
            await Log($" {GetSeverityString(severity)} ", GetSeverityColor(severity));
            await Log($" [{GetSourceString(src)}] ", ConsoleColor.DarkGray);

            if (!string.IsNullOrEmpty(message))
            {
                await Log($"{message}\n", ConsoleColor.White);
            }
            else if (exception.Message is null)
            {
                await Log($"Unknown \n{exception.StackTrace}\n", ConsoleColor.DarkRed);
            }
            else
            {
                await Log($"{exception.Message}\n{exception.StackTrace}\n", GetSeverityColor(severity));
            }
        }