示例#1
0
        private string Write(string message, Log_Severity severity = Log_Severity.Info)
        {
            string formattedMessage = (severity == Log_Severity.None) ? message : string.Format("{0}: {1}", severity.ToString(), message);

            foreach (ILogWriter writer in writers.Values)
            {
                writer.Write(severity, formattedMessage);
            }

            switch (severity)
            {
            case Log_Severity.Error:
            {
                if (CrashOnError)
                {
                    Shutdown();
                    Environment.Exit(0);
                }
            }
            break;

            case Log_Severity.Fatal:
            {
                Shutdown();
                Environment.Exit(0);
            }
            break;
            }

            return(formattedMessage);
        }
示例#2
0
        public void Write(Log_Severity severity, string value)
        {
            switch (severity)
            {
            case Log_Severity.Fatal:
                Console.ForegroundColor = ConsoleColor.Magenta;
                break;

            case Log_Severity.Error:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            case Log_Severity.Warning:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case Log_Severity.Info:
                Console.ForegroundColor = ConsoleColor.White;
                break;

            case Log_Severity.None:
                Console.ForegroundColor = ConsoleColor.DarkCyan;
                break;
            }

            output.WriteLine(value);
            output.Flush();

            Console.ForegroundColor = ConsoleColor.White;
        }
示例#3
0
        /// <summary>
        /// Write a message to the log. Requires user to state message severity. For general info message Write(string, params object[]) can be used
        /// </summary>
        /// <param name="severity">The severity of the error message</param>
        /// <param name="messageFormat">format of the string to pass into the log message</param>
        /// <param name="parameters">the parameters to accompany messageFormat</param>
        public string Write(Log_Severity severity, string messageFormat, params object[] parameters)
        {
            string formattedMessage;

            if (parameters.Length == 0)
            {
                formattedMessage = messageFormat;
            }
            else
            {
                formattedMessage = string.Format(messageFormat, parameters);
            }

            return(Write(formattedMessage, severity));
        }
示例#4
0
        public static Task Write(LogMessage msg)
        {
            Log_Severity ls = Log_Severity.None;

            // Map Discord.net LogSeverity to Log_Severity
            switch (msg.Severity)
            {
            case LogSeverity.Info:
                ls = Log_Severity.Info;
                break;

            case LogSeverity.Warning:
                ls = Log_Severity.Warning;
                break;

            case LogSeverity.Error:
                ls = Log_Severity.Error;
                break;

            case LogSeverity.Critical:
                ls = Log_Severity.Fatal;
                break;
            }

            if (msg.Exception == null)
            {
                AwLog.Instance.Write(msg.ToString());
            }
            else
            {
                if (ls == Log_Severity.Fatal)
                {
                    AwLog.Instance.WriteFatalException(msg.Exception, msg.Message);
                }
                else
                {
                    AwLog.Instance.WriteNonFatalException(msg.Exception, msg.Message);
                }
            }

            return(Task.CompletedTask);
        }
示例#5
0
        private string WriteException(Log_Severity severity, Exception ex, string additionalMessage = null)
        {
            if (additionalMessage == null)
            {
                string s = Write(severity, "{0}\r\nStack:\r\n{1}", ex.Message, ex.StackTrace);
                if (ex.InnerException != null)
                {
                    s += WriteException(severity, ex.InnerException);
                }

                return(s);
            }
            else
            {
                string s = Write(severity, "{0}\r\nException:\r\n{1}\r\nStack:\r\n{2}", additionalMessage, ex.Message, ex.StackTrace);
                if (ex.InnerException != null)
                {
                    s += WriteException(severity, ex.InnerException, additionalMessage);
                }

                return(s);
            }
        }
示例#6
0
 public static Task Write(Log_Severity severity, string msg)
 {
     AwLog.Instance.Write(severity, msg);
     return(Task.CompletedTask);
 }
示例#7
0
 public void Write(Log_Severity severity, string value)
 {
     output.WriteLine(value);
     output.Flush();
 }