Represents a message to log.
コード例 #1
0
ファイル: TerminalExtension.cs プロジェクト: hapm/IrcShark
        /// <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();
        }
コード例 #2
0
ファイル: Logger.cs プロジェクト: hapm/IrcShark
        /// <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();
            }
        }
コード例 #3
0
ファイル: StatusPanel.cs プロジェクト: hapm/IrcShark
 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();
     }
 }
コード例 #4
0
ファイル: StatusPanel.cs プロジェクト: hapm/IrcShark
 void Logger_LogLine(object sender, LogMessage args)
 {
     Log(args);
 }
コード例 #5
0
ファイル: ChannelFilter.cs プロジェクト: hapm/IrcShark
        /// <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;
            }
        }