Represents a message to log.
Ejemplo n.º 1
0
        /// <summary>
        /// This is a replacement logger for the <see cref="IrcSharkApplication.DefaultConsoleLogger" />.
        /// </summary>
        /// <remarks>
        /// The default loghandler is not compatible with the TerminalExtension and is replaced with this 
        /// loghandler.
        /// </remarks>
        /// <param name="sender">The Logger what send the message.</param>
        /// <param name="msg">The Message.</param>
        public void TerminalLogger(object sender, LogMessage msg)
        {
            LogHandlerSetting logSetting;
            try
            {
                logSetting = Context.Application.Settings.LogSettings["IrcShark.Extensions.TerminalLogHandler"];
            }
            catch (IndexOutOfRangeException)
            {
                logSetting = new LogHandlerSetting("IrcShark.Extensions.TerminalLogHandler");
                logSetting.Debug = false;
                logSetting.Warning = true;
                logSetting.Error = true;
                Context.Application.Settings.LogSettings.Add(logSetting);
                return;
            }

            if (!logSetting.ApplysTo(msg))
            {
                return;
            }

            string format = "[{0}][{1}][{2}] {3}";
            switch (msg.Level)
            {
                case LogLevel.Debug:
                    Console.ForegroundColor = ConsoleColor.Gray;
                    break;
                case LogLevel.Warning:
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    break;
                case LogLevel.Error:
                    Console.ForegroundColor = ConsoleColor.Red;
                    break;
            }

            WriteLine(format, msg.Time, msg.Channel, msg.Level.ToString(), msg.Message);
            Console.ResetColor();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Logs a new message to the logging system.
        /// </summary>
        /// <param name="msg">
        /// The <see cref="LogMessage"/> to log.
        /// </param>
        public void Log(LogMessage msg)
        {
            logMessageQueue.Enqueue(msg);
            if (logThread.ThreadState == ThreadState.Unstarted)
            {
                if (application.Settings == null)
                {
                    return;
                }

                logThread.Start();
            }

            if (logMessageQueue.Count > 0)
            {
                logAutoResetEvent.Set();
            }
        }
Ejemplo n.º 3
0
 void Log(LogMessage msg)
 {
     if (logBox.InvokeRequired)
         logBox.Invoke(new LogDelegate(Log), msg);
     else
     {
         string.Format("[{0}][{1}: {2}] {3}", msg.Created.ToShortTimeString(), msg.Level, msg.Subject, msg.Message);
         logBox.Select(logBox.Text.Length, 0);
         logBox.ScrollToCaret();
     }
 }
Ejemplo n.º 4
0
 void Logger_LogLine(object sender, LogMessage args)
 {
     Log(args);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Checks if the given <see cref="LogMessage" /> is filtered by this channel filter setting or not.
        /// </summary>
        /// <param name="msg">The message to check.</param>
        /// <returns>True if the message passes the filters, false otherwise.</returns>
        public bool ApplysTo(LogMessage msg)
        {
            if (msg.Channel != channelName)
            {
                return false;
            }

            switch (msg.Level)
            {
                case LogLevel.Debug:
                    return Debug;
                case LogLevel.Information:
                    return Information;
                case LogLevel.Warning:
                    return Warning;
                case LogLevel.Error:
                    return Error;
                default:
                    return false;
            }
        }