Exemple #1
0
        /// <summary>
        /// Logs a message and an exception to console.
        /// </summary>
        /// <param name="level">Log level.</param>
        /// <param name="logger">Source of the log message.</param>
        /// <param name="message">Log message.</param>
        /// <param name="exception">Exception to be included with log message.</param>
        public override void LogException(Logger.Level level, string logger, string message, Exception exception)
        {
            var timeStamp = this.IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";

            SetConsoleForegroundColor(level);
            Console.WriteLine(string.Format("{0}[{1}] [{2}]: {3} - [Exception] {4}", timeStamp, level.ToString().PadLeft(5), logger, message, exception));
        }
 public LogLine(Logger.Level level, string text, Type ownerType)
 {
     Level     = level;
     Text      = text;
     OwnerType = ownerType;
     Time      = DateTime.Now;
 }
Exemple #3
0
        /// <summary>
        /// Sets console's foreground color.
        /// </summary>
        /// <param name="level"></param>
        private static void SetConsoleForegroundColor(Logger.Level level)
        {
            switch (level)
            {
            case Logger.Level.Trace:
            case Logger.Level.PacketDump:
                Console.ForegroundColor = ConsoleColor.DarkGray;
                break;

            case Logger.Level.Debug:
                Console.ForegroundColor = ConsoleColor.Cyan;
                break;

            case Logger.Level.Info:
                Console.ForegroundColor = ConsoleColor.White;
                break;

            case Logger.Level.Warn:
                Console.ForegroundColor = ConsoleColor.Yellow;
                break;

            case Logger.Level.Error:
                Console.ForegroundColor = ConsoleColor.Magenta;
                break;

            case Logger.Level.Fatal:
                Console.ForegroundColor = ConsoleColor.Red;
                break;

            default:
                break;
            }
        }
Exemple #4
0
 public override void Log(string message, Logger.Level level)
 {
     if (ShouldLog(level))
     {
         Console.WriteLine(level.ToString().ToUpper() + ": " + message);
     }
 }
Exemple #5
0
        /// <summary>
        /// Logs a message to console.
        /// </summary>
        /// <param name="level">Log level.</param>
        /// <param name="logger">Source of the log message.</param>
        /// <param name="message">Log message.</param>
        public override void LogMessage(Logger.Level level, string logger, string message)
        {
            var    timeStamp   = this.IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
            string finalString = string.Format("{0}[{1}] {2}", timeStamp, level.ToString(), message);

            Window.ServerForm.Instance.AddTextToFastColoredTextBox(finalString + Environment.NewLine, level);
        }
Exemple #6
0
 /// <summary>
 /// Prints an entry to the associated file.
 /// </summary>
 /// <param name="level">the <see cref="Logger.Level"/> of the message</param>
 /// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
 /// <param name="logName">the name of the log that sent the message</param>
 /// <param name="message">the message to print</param>
 public override void Print(Logger.Level level, DateTime time, string logName, string message)
 {
     foreach (var line in message.Split(new[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
     {
         FileWriter.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper());
     }
 }
        private void LogToListView(Logger.Level level, string text)
        {
            // Handle case of LogToListView being called outside the main thread.
            if (InvokeRequired)
            {
                Invoke(new Action <Logger.Level, string>(LogToListView), new object[] { level, text });
                return;
            }

            // Prevent the list from growing forever.
            if (listViewLog.Items.Count > 200)
            {
                listViewLog.Items.RemoveAt(0);
            }

            // Colour based on warning level
            ListViewItem item = new ListViewItem(text);

            if (level == Logger.Level.Warning)
            {
                item.BackColor = Color.Orange;
            }
            else if (level == Logger.Level.Error)
            {
                item.BackColor = Color.Red;
            }

            listViewLog.Items.Add(item);

            // Automatically scroll to the bottom of the list as more entries are added.
            listViewLog.TopItem = listViewLog.Items[listViewLog.Items.Count - 1];
        }
Exemple #8
0
 public override void write(string text, Logger.Level level = Logger.Level.Info)
 {
     if (level <= this.level)
     {
         Console.Error.WriteLine(this.getTime + text);
     }
 }
Exemple #9
0
        private static void SetForeGroundColor(Logger.Level level)
        {
            switch (level)
            {
            case Logger.Level.Dump:
                System.Console.ForegroundColor = System.ConsoleColor.DarkGray;
                break;

            case Logger.Level.Trace:
                System.Console.ForegroundColor = System.ConsoleColor.DarkGray;
                break;

            case Logger.Level.Debug:
                System.Console.ForegroundColor = System.ConsoleColor.Cyan;
                break;

            case Logger.Level.Info:
                System.Console.ForegroundColor = System.ConsoleColor.White;
                break;

            case Logger.Level.Warn:
                System.Console.ForegroundColor = System.ConsoleColor.Yellow;
                break;

            case Logger.Level.Error:
                System.Console.ForegroundColor = System.ConsoleColor.Magenta;
                break;

            case Logger.Level.Fatal:
                System.Console.ForegroundColor = System.ConsoleColor.Red;
                break;
            }
        }
Exemple #10
0
 /// <summary>
 /// Prints an entry to the associated file.
 /// </summary>
 /// <param name="level">the <see cref="Logger.Level"/> of the message</param>
 /// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
 /// <param name="logName">the name of the log that sent the message</param>
 /// <param name="message">the message to print</param>
 public override void Print(Logger.Level level, DateTime time, string logName, string message)
 {
     foreach (var line in removeControlCodes.Replace(message, "").Split(new[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
     {
         FileWriter.WriteLine("[{2} @ {1:HH:mm:ss}] {0}", line, time, level.ToString().ToUpper());
     }
 }
Exemple #11
0
        public override void LogException(Logger.Level level, string logger, string message, System.Exception exception)
        {
            bool flag = false;

            try
            {
#if NET4
                System.Threading.Monitor.Enter(this, ref flag);
#else
                System.Threading.Monitor.Enter(this);
                flag = true;
#endif
                string text = base.IncludeTimeStamps ? ("[" + System.DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] ") : "";
                if (!this._disposed)
                {
                    this._logStream.WriteLine(string.Format("{0}[{1}] [{2}]: {3} - [Exception] {4}", new object[]
                    {
                        text,
                        level.ToString().PadLeft(5),
                        logger,
                        message,
                        exception
                    }));
                }
            }
            finally
            {
                if (flag)
                {
                    System.Threading.Monitor.Exit(this);
                }
            }
        }
        public override void LogMessage(Logger.Level level, string logger, string message)
        {
            if (true)
            {
                string timeStamp  = IncludeTimeStamps ? "[" + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss.fff") + "] " : "";
                string logMessage = $"{timeStamp}[{level.ToString().PadLeft(5)}] [{logger}]: {message}";

                switch (level)
                {
                case Logger.Level.Debug:
                case Logger.Level.Trace:
                case Logger.Level.Info:
                    UnityEngine.Debug.Log(logMessage);
                    break;

                case Logger.Level.Warn:
                    UnityEngine.Debug.LogWarning(logMessage);
                    break;

                case Logger.Level.Error:
                case Logger.Level.Fatal:
                    UnityEngine.Debug.LogError(logMessage);
                    break;
                }
            }
        }
 public ThreadQueue(string name, Logger.Level loggerLevel, int maxThreads)
 {
     _QueueName       = name;
     logger           = new Logger(loggerLevel);
     threadController = new ThreadController(_QueueName, loggerLevel, maxThreads);
     new Thread(() => ConsumeItems()).Start();
 }
Exemple #14
0
 public LogEntry(string sender, Logger.Level severenety, string message, string location)
 {
     Sender     = sender;
     Severenety = severenety;
     Message    = message;
     Location   = location;
     Time       = DateTime.Now;
 }
 void Logger_LogEvent(Logger.Level level, string message)
 {
     if (level > Logger.Level.Debug)
     {
         Console.WriteLine("{0} [{1}] {2}", DateTime.Now, level.ToString().ToUpper(), message);
         logFile.WriteLine("{0} [{1}] {2}", DateTime.Now, level.ToString().ToUpper(), message);
     }
 }
Exemple #16
0
 /// <summary>
 /// Initialized thread controller
 /// </summary>
 /// <param name="name">Name of the System</param>
 /// <param name="loggerLevel">Log output level</param>
 /// <param name="maxThreads">Max concurrent threads allowed</param>
 public ThreadController(string name, Logger.Level loggerLevel, int maxThreads)
 {
     MAX_THREADS      = maxThreads;
     _ControllerName  = name;
     logger           = new Logger(loggerLevel);
     controllerThread = new Thread(() => RunController());
     controllerThread.Start();
 }
Exemple #17
0
        public static void Log(Logger.Level level, string message)
        {
            if (string.IsNullOrEmpty(message))
            {
                message = string.Empty;
            }

            Console.WriteLine(string.Format("{0}\t{1}", level.ToString(), message));
        }
 public LogMessage(Logger.Level level, string text, DateTime dateTime, string callingClass, string callingMethod, int lineNumber)
 {
     Level         = level;
     Text          = text;
     DateTime      = dateTime;
     CallingClass  = callingClass;
     CallingMethod = callingMethod;
     LineNumber    = lineNumber;
 }
Exemple #19
0
        private void SetLogLevel(Logger.Level level)
        {
            logFineMenuItem.Checked    = level == Logger.Level.Fine;
            logInfoMenuItem.Checked    = level == Logger.Level.Info;
            logWarningMenuItem.Checked = level == Logger.Level.Warning;
            logErrorMenuItem.Checked   = level == Logger.Level.Error;

            Context.Logger.LogLevel = level;
        }
 /// <summary>
 /// </summary>
 /// <param name="fileName"></param>
 /// <param name="level"></param>
 /// <param name="format"></param>
 /// <param name="timeFormat"></param>
 public FileLogHandler(
     string fileName,
     Logger.Level level,
     string format,
     string timeFormat = DefaultTimeFormat
     )
     : this(fileName, format, timeFormat)
 {
     Level = level;
 }
        public void Log(string message, Logger.Level level)
        {
            FrontendLogMessage logMessage = new FrontendLogMessage()
            {
                Message  = message,
                LogLevel = level
            };

            _worker.SendToFrontend(logMessage);
        }
Exemple #22
0
        public Logger(string logPath, Logger.Level level)
        {
            logFilePath = logPath;
            logLevel    = level;

            using (var writer = new StreamWriter(logFilePath, true))
            {
                writer.WriteLine("Logger Initialised");
                writer.Close();
            }
        }
 private void _Log(Logger.Level level, string msg, params object[] args)
 {
     if (_Logger != null)
     {
         lock (_Logger)
         {
             string m = string.Format(msg, args);
             _Logger.Log(m, level);
         }
     }
 }
Exemple #24
0
        private static void _Log(string message, Logger.Level logLevel, string filePath, string member, int line)
        {
#if DEBUG
            var pathParts = filePath.Split('\\');
            var className = pathParts[pathParts.Length - 1].Replace(".cs", "");
            var prefix    = $"[{className}.{member}():{line}]: ".PadRight(62);
            IpaLogger.Log(logLevel, $"{prefix}{message}");
#else
            IpaLogger.Log(logLevel, message);
#endif
        }
Exemple #25
0
 /// <summary>
 /// Prints an entry to standard out.
 /// </summary>
 /// <param name="level">the <see cref="Logger.Level"/> of the message</param>
 /// <param name="time">the <see cref="DateTime"/> the message was recorded at</param>
 /// <param name="logName">the name of the log that sent the message</param>
 /// <param name="message">the message to print</param>
 public override void Print(Logger.Level level, DateTime time, string logName, string message)
 {
     if (((byte)level & (byte)StandardLogger.PrintFilter) == 0)
     {
         return;
     }
     foreach (var line in message.Split(new[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
     {
         Console.WriteLine(Logger.LogFormat, line, logName, time, level.ToString().ToUpper());
     }
 }
Exemple #26
0
        public static void log(Logger.Level logLevel, string message, params object[] args)
        {
            string logMessage = message;

            if (args.Length > 0)
            {
                logMessage = string.Format(message, args);
            }

            Logger.Log(logLevel, logMessage);
        }
 void ILogReceiver.LogReceived(Logger.Level level, string msg)
 {
     if (InvokeRequired)
     {
         Invoke(new Action(() => textBox1.Text += msg + Environment.NewLine));
     }
     else
     {
         textBox1.Text += msg + Environment.NewLine;
     }
 }
 static void LoggingHandler(Logger.Level level, string message, IDictionary <string, object> args)
 {
     if (args != null)
     {
         foreach (string key in args.Keys)
         {
             message += String.Format(" {0}: {1},", "" + key, "" + args[key]);
         }
     }
     Console.WriteLine(String.Format("[ActionTests] [{0}] {1}", level, message));
 }
Exemple #29
0
 public static void Log(Logger.Level level = Logger.Level.NONE, string message = "")
 {
     if (logger != null)
     {
         logger.Log(level, message);
     }
     else
     {
         Console.WriteLine(Logger.Level_ToString(level) + message);
     }
 }
 internal static void Log(Logger.Level lvl, string message)
 { // multiple proxy methods to delay loading of assemblies until it's done
     if (Logger.LogCreated)
     {
         AssemblyLibLoaderCallLogger(lvl, message);
     }
     else
     if (((byte)lvl & (byte)StandardLogger.PrintFilter) != 0)
     {
         Console.WriteLine($"[{lvl}] {message}");
     }
 }
 /// <summary>
 /// Constructs the factory
 /// </summary>
 public ConsoleLoggerFactory(Logger.Level minLevel = Logger.Level.Info)
 {
     _minLevel = minLevel;
 }
 /// <summary>
 /// Creates the logger factory
 /// </summary>
 public DebugLoggerFactory(Logger.Level minLevel = Logger.Level.Debug)
 {
     _minLevel = minLevel;
 }
Exemple #33
0
			public LoggerMessage(Logger.Level eLevel, string sMessage)
			{
				dt = DateTime.Now;
				this.eLevel = eLevel;
				this.sMessage = sMessage;
			}
        /// <summary>
        /// Initialize environment, loads settings from INI file
        /// </summary>
        public static bool Init()
        {
            //where are we running?
            Settings.ProgramBasePath = Path.GetDirectoryName(Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path));

            //path where log file is saved, inside program's folder, can't be specified by user
            Settings.LogFilePath = Path.Combine(Settings.ProgramBasePath, LogFileName);

            //if INI doesn't exists, create a new empty text file
            var iniFilePath = Path.Combine(Settings.ProgramBasePath, IniFileName);
            if (!File.Exists(iniFilePath))
            {
                File.AppendAllText(iniFilePath, string.Empty);
            }

            //set the object that will do IO to the INI file
            IniManager = new INIFile((iniFilePath), true, true);

            //log level: if not specified, set on warning and above
            var logLevel = IniManager.GetValue(IniSections.Options, IniKeys.LogLevel, "war").ToLowerInvariant().Substring(0, 3);
            switch (logLevel)
            {
                case "trc":
                case "tra":
                    Settings.LogLevel = Logger.Level.Trace;
                    break;
                case "inf":
                    Settings.LogLevel = Logger.Level.Information;
                    break;
                case "err":
                    Settings.LogLevel = Logger.Level.Error;
                    break;
                case "deb":
                case "dbg":
                    Settings.LogLevel = Logger.Level.Debug;
                    break;
                case "war":
                case "wrn":
                default:
                    Settings.LogLevel = Logger.Level.Warning;
                    break;
            }

            #if DEBUG
            //setting log level to trace during development
            Settings.LogLevel = Logger.Level.Trace;
            #endif

            //the furk api key is mandatory, otherwise we can't connect to the seedbox
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.FurkApiKey);

            Settings.FurkApiKey = IniManager.GetValue(IniSections.Options, IniKeys.FurkApiKey, string.Empty);
            if (string.IsNullOrWhiteSpace(Settings.FurkApiKey))
            {
                Logger.Error("Furk API key is missing in configuration file. It must be specified in [Options] section, FurkApiKey=your_api_key. Program will now shut down.");
                return false;
            }
            Logger.Trace("Loaded setting: {0}.{1}={2}", IniSections.Options, IniKeys.FurkApiKey, Settings.FurkApiKey);

            //from here on, every parameter is optional; we add the keys to the file without any specified value

            //when the following keywords are found within a torrent name, torrent is processed (when empty doesn't have any effect)
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.IncludeTorrentsWithKeywords);
            Settings.IncludeTorrentsWithKeywords = Settings.ConvertIniValueToList(IniSections.Options, IniKeys.IncludeTorrentsWithKeywords);

            //when the following keywords are found within a torrent name, torrent is excluded (when empty doesn't have any effect)
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.ExcludeTorrentsWithKeywords);
            Settings.ExcludeTorrentsWithKeywords = Settings.ConvertIniValueToList(IniSections.Options, IniKeys.ExcludeTorrentsWithKeywords);

            //when the following keywords are found within a file name, file is processed (when empty doesn't have any effect)
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.IncludeFilesWithKeywords);
            Settings.IncludeFilesWithKeywords = Settings.ConvertIniValueToList(IniSections.Options, IniKeys.IncludeFilesWithKeywords);

            //when the following keywords are found within a file name, file is excluded (when empty doesn't have any effect)
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.ExcludeFilesWithKeywords);
            Settings.ExcludeFilesWithKeywords = Settings.ConvertIniValueToList(IniSections.Options, IniKeys.ExcludeFilesWithKeywords);

            //how many downloads must run at the same time? Default is 1
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.MaxConcurrentDownloads);
            Settings.MaxConcurrentDownloads = IniManager.GetValue(IniSections.Options, IniKeys.MaxConcurrentDownloads, 1);

            //what's the maximum size for a torrent to be processed?
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.MaxTorrentSize);
            Settings.MaxTorrentSize = IniManager.GetValue(IniSections.Options, IniKeys.MaxTorrentSize, -1);

            //what's the maximum size for a file to be processed?
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.MaxFileSize);
            Settings.MaxFileSize = IniManager.GetValue(IniSections.Options, IniKeys.MaxFileSize, -1);

            //program can notify via PushBullet; in this case, an API key is required
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.PushbulletApiKey);
            Settings.PushbulletApiKey = IniManager.GetValue(IniSections.Options, IniKeys.PushbulletApiKey, string.Empty);

            //when PushBullet is enabled, messages can be sent on only one device instead of every registered device
            Settings.CreateIniKeyIfEmpty(IniSections.Options, IniKeys.PushbulletDeviceName);
            Settings.PushbulletDeviceName = IniManager.GetValue(IniSections.Options, IniKeys.PushbulletDeviceName, string.Empty);

            //machine specific options
            Settings.MachineName = Environment.MachineName;
            var computerSpecificSection = string.Format("{0}{1}", IniSections.ComputerNamePrefix, Settings.MachineName);

            //machine specific temporary ad final path
            Settings.CreateIniKeyIfEmpty(computerSpecificSection, IniKeys.LocalPath);
            var userLocalPath = IniManager.GetValue(computerSpecificSection, IniKeys.LocalPath, string.Empty);
            Settings.CreateIniKeyIfEmpty(computerSpecificSection, IniKeys.RemotePath);
            var userRemotePath = IniManager.GetValue(computerSpecificSection, IniKeys.RemotePath, string.Empty);

            //default local path
            var defaultLocalPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), Settings.DefaultDownloadsFolderName);

            var tryUseDefaultLocalPath = false;
            //user specified a local path
            if (!string.IsNullOrWhiteSpace(userLocalPath))
            {
                //check if that path exists
                if (Directory.Exists(userLocalPath))
                {
                    //specified path exists, check if it's writeable
                    if (Settings.IsDirectoryWriteable(userLocalPath))
                    {
                        Settings.LocalPath = userLocalPath;
                    }
                    else
                    {
                        //if a path is provided and exists but can't be written, fall back to default
                        Logger.Error("Provided LocalPath [{0}] can't be written, default will be used [{1}] ", userLocalPath, defaultLocalPath);
                        tryUseDefaultLocalPath = true;
                    }
                }
                else
                {
                    //if provided path does not exists, fall back to default
                    Logger.Error("Provided LocalPath [{0}] does not exists, default will be used [{1}] ", userLocalPath, defaultLocalPath);
                    tryUseDefaultLocalPath = true;
                }
            }
            else
            {
                //if nothing is provided, fall back to default
                tryUseDefaultLocalPath = true;
            }

            //if default local path should be used, check if it's writeable
            if (tryUseDefaultLocalPath)
            {
                Settings.LocalPath = defaultLocalPath;
                if (!Directory.Exists(defaultLocalPath))
                {
                    //try creating directory
                    try
                    {
                        Directory.CreateDirectory(defaultLocalPath);
                        Logger.Info("Default local path '{0}' succesfully created", defaultLocalPath);
                    }
                    catch
                    {
                        Logger.Error("Error creating default local path '{0}', program can't continue", defaultLocalPath);
                        return false;
                    }

                }
                if (!Settings.IsDirectoryWriteable(defaultLocalPath))
                {
                    Logger.Error("Default LocalPath [{0}] can't be written, program can't continue", defaultLocalPath);
                    return false;
                }
            }

            //if user also specified a remote path, check it
            if (!string.IsNullOrWhiteSpace(userRemotePath))
            {
                if (Directory.Exists(userRemotePath))
                {
                    if (Settings.IsDirectoryWriteable(userRemotePath))
                    {
                        Settings.RemotePath = userRemotePath;
                        Settings.CanUseRemotePath = true;
                    }
                    else
                    {
                        Logger.Error("Provided RemotePath [{0}] is reachable but can't be written, setting will be ignored", userRemotePath);
                    }
                }
                else
                {
                    Logger.Warn("Provided RemotePath [{0}] does not exists or it's not reachable at the moment, setting will be ignored", userRemotePath);
                }
            }

            //when path parsing and checking is finished, notify paths currently in use
            Logger.Info("Local path is {0}", Settings.LocalPath);
            if (Settings.CanUseRemotePath)
                Logger.Info("Remote path is {0}", Settings.RemotePath);
            else
                Logger.Info("Remote path is not in use");

            //history items

            Settings.CreateIniKeyIfEmpty(IniSections.ApplicationData, IniKeys.HistoryItemsCount);
            var historyItemsCount = IniManager.GetValue(IniSections.ApplicationData, IniKeys.HistoryItemsCount, 0);
            for (int i = 0; i < historyItemsCount; i++)
            {
                var historyItem = IniManager.GetValue(IniSections.ApplicationData, IniKeys.HistoryItemPrefix + i.ToString(), string.Empty);
                Settings.DownloadsHistory.Add(historyItem);
            }

            return true;
        }