Example #1
0
        /// <summary>
        ///     Log a specific message by LogLevel. Won't log if the LogLevel is greater than the maxLogLevel set.
        /// </summary>
        /// <param name="message">The message to log. The current time will be prepended.</param>
        /// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
        /// <param name="color">Optional. Default is auotmatic</param>
        public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black)
        {
            // Remember to change to a font that supports your language, otherwise it'll still show as ???.
            Console.OutputEncoding = Encoding.UTF8;
            if (level > _maxLogLevel)
            {
                return;
            }

            var finalMessage = Logger.GetFinalMessage(message.Replace("NecroBot", "RocketBot"), level, color);

            Console.WriteLine(finalMessage);

            // Fire log write event.
            OnLogWrite?.Invoke(this, new LogWriteEventArgs {
                Message = finalMessage, Level = level, Color = color
            });

            // ReSharper disable once SwitchStatementMissingSomeCases
            Color _color = new Color();
            Dictionary <LogLevel, Color> colors = new Dictionary <LogLevel, Color>()
            {
                { LogLevel.Error, Color.Red },
                { LogLevel.Caught, Color.Green },
                { LogLevel.Info, Color.DarkCyan },
                { LogLevel.Warning, Color.FromArgb(255, 128, 128, 0) },
                { LogLevel.Pokestop, Color.Cyan },
                { LogLevel.Farming, Color.Magenta },
                { LogLevel.Sniper, Color.White },
                { LogLevel.Recycling, Color.DarkMagenta },
                { LogLevel.Flee, Color.FromArgb(255, 128, 128, 0) },
                { LogLevel.Transfer, Color.DarkGreen },
                { LogLevel.Evolve, Color.DarkGreen },
                { LogLevel.Berry, Color.FromArgb(255, 128, 128, 0) },
                { LogLevel.Egg, Color.FromArgb(255, 128, 128, 0) },
                { LogLevel.Debug, Color.Gray },
                { LogLevel.Update, Color.White },
                { LogLevel.New, Color.Green },
                { LogLevel.SoftBan, Color.Red },
                { LogLevel.LevelUp, Color.Magenta },
                { LogLevel.BotStats, Color.Magenta },
                { LogLevel.Gym, Color.Magenta },
                { LogLevel.GymDisk, Color.Cyan },
                { LogLevel.Service, Color.White }
            };

            _color = colors[level];

            if (string.IsNullOrEmpty(color.ToString()) || color.ToString() != "Black")
            {
                _color = FromColor(color);
            }

            if (string.IsNullOrEmpty(_color.ToString()))
            {
                _color = Color.White;
            }

            MainForm.ColoredConsoleWrite(_color, finalMessage);
        }
Example #2
0
 public static void Write(string from, string type, object content, LogLevel level = LogLevel.Info)
 {
     lock (Lock)
     {
         Init();
         using (var sw = new StreamWriter(LogFile, true))
         {
             var str = $"[{DateTime.Now:T}] [{type}] [INFO]: {content}";
             //Console.WriteLine(str);
             sw.WriteLine(str);
         }
     }
     OnLogWrite?.Invoke(from, type, content, level);
 }
Example #3
0
        public override void WriteLine(string value)
        {
            if (Disposed)
            {
                return;
            }

            ConsoleOut?.WriteLine(value);

            var fullEntry = '[' + DateTime.UtcNow.ToString("T", CultureInfo.InvariantCulture) + ']' + value;

            base.WriteLine(fullEntry);

            try
            {
                OnLogWrite?.Invoke(this, new LogEventArgs(fullEntry));
            }
            catch (Exception ex)
            {
                base.WriteLine("Exception in OnLogWrite subscriber - " + ex.ToStringDemystified());
            }
        }
Example #4
0
        protected override void Write(LogEventInfo logEvent)
        {
            string msg = Layout.Render(logEvent).Replace("|", " ");

            if (OnLogWrite != null)
            {
                MateriaLogLevel level = MateriaLogLevel.All;

                if (logEvent.Level.Ordinal == 0)
                {
                    level = MateriaLogLevel.Trace;
                }
                else if (logEvent.Level.Ordinal == 1)
                {
                    level = MateriaLogLevel.Debug;
                }
                else if (logEvent.Level.Ordinal == 2)
                {
                    level = MateriaLogLevel.Info;
                }
                else if (logEvent.Level.Ordinal == 3)
                {
                    level = MateriaLogLevel.Warn;
                }
                else if (logEvent.Level.Ordinal == 4)
                {
                    level = MateriaLogLevel.Error;
                }
                else if (logEvent.Level.Ordinal == 5)
                {
                    level = MateriaLogLevel.Fatal;
                }

                if (OnLogWrite != null)
                {
                    OnLogWrite.Invoke(level, msg);
                }
            }
        }
Example #5
0
        /// <summary>
        ///     Log a specific message by LogLevel. Won't log if the LogLevel is greater than the maxLogLevel set.
        /// </summary>
        /// <param name="message">The message to log. The current time will be prepended.</param>
        /// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
        /// <param name="color">Optional. Default is auotmatic</param>
        public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black)
        {
            // Remember to change to a font that supports your language, otherwise it'll still show as ???.
            if (level > _maxLogLevel)
            {
                return;
            }

            // Fire log write event.
            OnLogWrite?.Invoke(this, new LogWriteEventArgs {
                Message = message, Level = level, Color = color
            });
            message = message + "\r\n";
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (level)
            {
            case LogLevel.Error:
                MainForm.ColoredConsoleWrite(Color.Red,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
                break;

            case LogLevel.Warning:
                MainForm.ColoredConsoleWrite(Color.Goldenrod,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Attention}) {message}");
                break;

            case LogLevel.Info:
                MainForm.ColoredConsoleWrite(Color.DarkCyan,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Info}) {message}");
                break;

            case LogLevel.Pokestop:
                MainForm.ColoredConsoleWrite(Color.Cyan,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pokestop}) {message}");
                break;

            case LogLevel.Farming:
                MainForm.ColoredConsoleWrite(Color.Magenta,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Farming}) {message}");
                break;

            case LogLevel.Sniper:
                MainForm.ColoredConsoleWrite(Color.White,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Sniper}) {message}");
                break;

            case LogLevel.Recycling:
                MainForm.ColoredConsoleWrite(Color.DarkMagenta,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Recycling}) {message}");
                break;

            case LogLevel.Caught:
                MainForm.ColoredConsoleWrite(Color.Green,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
                break;

            case LogLevel.Transfer:
                MainForm.ColoredConsoleWrite(Color.DarkGreen,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Transferred}) {message}");
                break;

            case LogLevel.Evolve:
                MainForm.ColoredConsoleWrite(Color.Yellow,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Evolved}) {message}");
                break;

            case LogLevel.LevelUp:
                MainForm.ColoredConsoleWrite(Color.Yellow,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.LevelUp}) {message}");
                break;

            case LogLevel.Berry:
                MainForm.ColoredConsoleWrite(Color.DarkGoldenrod,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Berry}) {message}");
                break;

            case LogLevel.Egg:
                MainForm.ColoredConsoleWrite(Color.DarkGoldenrod,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Egg}) {message}");
                break;

            case LogLevel.Debug:
                MainForm.ColoredConsoleWrite(Color.Gray,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Debug}) {message}");
                break;

            case LogLevel.Update:
                MainForm.ColoredConsoleWrite(Color.White,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Update}) {message}");
                break;

            case LogLevel.New:
                MainForm.ColoredConsoleWrite(Color.Green,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.New}) {message}");
                break;

            default:
                MainForm.ColoredConsoleWrite(Color.White,
                                             $"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
                break;
            }
        }
Example #6
0
        /// <summary>
        ///     Log a specific message by LogLevel. Won't log if the LogLevel is greater than the maxLogLevel set.
        /// </summary>
        /// <param name="message">The message to log. The current time will be prepended.</param>
        /// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
        /// <param name="color">Optional. Default is auotmatic</param>
        public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black)
        {
            // Remember to change to a font that supports your language, otherwise it'll still show as ???.
            //TODO: requis for RocketBot2 IO.Execption
            //Console.OutputEncoding = Encoding.UTF8;
            if (level > _maxLogLevel)
            {
                return;
            }

            var finalMessage = Logger.GetFinalMessage(message, level, color);

            //  Console.WriteLine(finalMessage);

            // Fire log write event.
            OnLogWrite?.Invoke(this, new LogWriteEventArgs {
                Message = finalMessage, Level = level, Color = color
            });

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (level)
            {
            case LogLevel.Berry:
                MainForm.ColoredConsoleWrite(Color.Yellow, finalMessage);
                break;

            case LogLevel.Caught:
                MainForm.ColoredConsoleWrite(Color.GreenYellow, finalMessage);
                break;

            case LogLevel.Debug:
                MainForm.ColoredConsoleWrite(Color.Gray, finalMessage);
                break;

            case LogLevel.Egg:
                MainForm.ColoredConsoleWrite(Color.LightGreen, finalMessage);
                break;

            case LogLevel.Error:
                MainForm.ColoredConsoleWrite(Color.Red, finalMessage);
                break;

            case LogLevel.Evolve:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;

            case LogLevel.Farming:
                MainForm.ColoredConsoleWrite(Color.Magenta, finalMessage);
                break;

            case LogLevel.Flee:
                MainForm.ColoredConsoleWrite(Color.Orange, finalMessage);
                break;

            case LogLevel.Gym:
                MainForm.ColoredConsoleWrite(Color.Magenta, finalMessage);
                break;

            case LogLevel.Info:
                MainForm.ColoredConsoleWrite(Color.Aqua, finalMessage);
                break;

            case LogLevel.LevelUp:
                MainForm.ColoredConsoleWrite(Color.Azure, finalMessage);
                break;

            case LogLevel.New:
                MainForm.ColoredConsoleWrite(Color.Green, finalMessage);
                break;

            case LogLevel.None:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;

            case LogLevel.Pokestop:
                MainForm.ColoredConsoleWrite(Color.Chartreuse, finalMessage);
                break;

            case LogLevel.Recycling:
                MainForm.ColoredConsoleWrite(Color.Magenta, finalMessage);
                break;

            case LogLevel.Service:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;

            case LogLevel.Sniper:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;

            case LogLevel.SoftBan:
                MainForm.ColoredConsoleWrite(Color.Red, finalMessage);
                break;

            case LogLevel.Transfer:
                MainForm.ColoredConsoleWrite(Color.Aquamarine, finalMessage);
                break;

            case LogLevel.Update:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;

            case LogLevel.Warning:
                MainForm.ColoredConsoleWrite(Color.Yellow, finalMessage);
                break;

            default:
                MainForm.ColoredConsoleWrite(Color.White, finalMessage);
                break;
            }
        }
Example #7
0
        /// <summary>
        /// Log a specific message by LogLevel. Won't log if the LogLevel is greater than the maxLogLevel set.
        /// </summary>
        /// <param name="message">The message to log. The current time will be prepended.</param>
        /// <param name="level">Optional. Default <see cref="LogLevel.Info" />.</param>
        /// <param name="color">Optional. Default is auotmatic</param>
        public void Write(string message, LogLevel level = LogLevel.Info, ConsoleColor color = ConsoleColor.Black)
        {
            // Remember to change to a font that supports your language, otherwise it'll still show as ???.
            Console.OutputEncoding = Encoding.UTF8;
            if (level > _maxLogLevel)
            {
                return;
            }

            // Fire log write event.
            OnLogWrite?.Invoke(this, new LogWriteEventArgs()
            {
                Message = message, Level = level, Color = color
            });

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (level)
            {
            case LogLevel.Error:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Red : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
                break;

            case LogLevel.Warning:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkYellow : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Attention}) {message}");
                break;

            case LogLevel.Info:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkCyan : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Info}) {message}");
                break;

            case LogLevel.Pokestop:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Cyan : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pokestop}) {message}");
                break;

            case LogLevel.Farming:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Magenta : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Farming}) {message}");
                break;

            case LogLevel.Sniper:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.White : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Sniper}) {message}");
                break;

            case LogLevel.Recycling:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkMagenta : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Recycling}) {message}");
                break;

            case LogLevel.Caught:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Green : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
                break;

            case LogLevel.Flee:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkYellow : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
                break;

            case LogLevel.Transfer:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkGreen : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Transferred}) {message}");
                break;

            case LogLevel.Evolve:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkGreen : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Evolved}) {message}");
                break;

            case LogLevel.Berry:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkYellow : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Berry}) {message}");
                break;

            case LogLevel.Egg:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.DarkYellow : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Egg}) {message}");
                break;

            case LogLevel.Debug:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Gray : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Debug}) {message}");
                break;

            case LogLevel.Update:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.White : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Update}) {message}");
                break;

            case LogLevel.New:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Green : color;
                Console.WriteLine($"[{DateTime.Now.ToString( "HH:mm:ss" )}] ({LoggingStrings.New}) {message}");
                break;

            case LogLevel.SoftBan:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Red : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.SoftBan}) {message}");
                break;

            case LogLevel.LevelUp:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.Magenta : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Pkmn}) {message}");
                break;

            default:
                Console.ForegroundColor = color == ConsoleColor.Black ? ConsoleColor.White : color;
                Console.WriteLine($"[{DateTime.Now.ToString("HH:mm:ss")}] ({LoggingStrings.Error}) {message}");
                break;
            }
        }