Пример #1
0
        private static void log(VRChatApi.Logging.LogLevel logLevel, bool lines = false, params object[] msgs) // [CallerMemberName] string cName = "Unknown.Unknown",
        {
            string     timestamp = DateTime.UtcNow.ToString("HH:mm:ss.fff", System.Globalization.CultureInfo.InvariantCulture);
            StackFrame frame = new StackFrame(2); var method = frame.GetMethod(); var cName = method.DeclaringType.Name; var mName = method.Name;

            System.ConsoleColor oldColor = ConsoleColor.White;
            try { oldColor = Console.ForegroundColor; } catch (IOException) {  }
            var newColor = ColorFromLogLevel(logLevel);
            var item     = new System.Windows.Forms.ListViewItem();

            item.ForeColor = newColor.Item1;
            var str       = "";
            var seperator = lines ? Environment.NewLine : " ";

            foreach (var _msg in msgs)
            {
                var msg = _msg;
                try {
                    var type = msg.GetType();
                    if (type.IsArray)
                    {
                        msg = string.Join(", ", _msg).Brackets();
                    }
                    str += seperator + (string)msg;
                } catch (Exception) {
                    // Console.WriteLine($"Error {ex.ToString()}");
                    str += seperator + msg.ToString();
                }
            }
            var line = $"[{timestamp}] {logLevel} - {cName}.{mName}: {str}";

            if (Main.selflog != null)
            {
                item.Text = line;
                try { Main.selflog.Items.Add(item); } catch (Exception) { }
            }
            if (Main.statusBar != null && logLevel > VRChatApi.Logging.LogLevel.Debug)
            {
                try {
                    Main.statusBar.Text      = line;
                    Main.statusBar.ForeColor = newColor.Item1;
                } catch (InvalidOperationException) { }
            }
            getLogFile().AppendLine(line);
            bool IsVerbose = false;

            try { IsVerbose = Program.Arguments.Launcher.Verbose.IsTrue; } catch (Exception) { };
            if (logLevel > VRChatApi.Logging.LogLevel.Trace || IsVerbose)
            {
                try {
                    Console.ForegroundColor = newColor.Item2;
                    Console.WriteLine(line);
                    Console.ForegroundColor = oldColor;
                } catch { }
            }
        }
Пример #2
0
        private static Tuple <Color, ConsoleColor> ColorFromLogLevel(VRChatApi.Logging.LogLevel logLevel)
        {
            switch (logLevel)
            {
            case VRChatApi.Logging.LogLevel.Trace:
                return(new Tuple <Color, ConsoleColor>(Color.Gray, ConsoleColor.Gray));

            case VRChatApi.Logging.LogLevel.Debug:
                return(new Tuple <Color, ConsoleColor>(Color.Cyan, ConsoleColor.Cyan));

            case VRChatApi.Logging.LogLevel.Warn:
                return(new Tuple <Color, ConsoleColor>(Color.Orange, ConsoleColor.DarkYellow));

            case VRChatApi.Logging.LogLevel.Error:
                return(new Tuple <Color, ConsoleColor>(Color.Red, ConsoleColor.Red));

            case VRChatApi.Logging.LogLevel.Fatal:
                return(new Tuple <Color, ConsoleColor>(Color.DarkRed, ConsoleColor.DarkRed));

            default:
                return(new Tuple <Color, ConsoleColor>(Color.White, ConsoleColor.White));
            }
        }