/// <summary> /// Initializes a new instance of the ChannelFilter class. /// </summary> /// <param name="channel">The name of the channel, this filter applys to.</param> /// <param name="defaults">The setting base, this filter belongs to.</param> /// <remarks> /// The filter is copied from the defaults. /// </remarks> internal ChannelFilter(string channel, LogHandlerSetting defaults) { this.channelName = channel; this.defaultFilter = defaults; this.CopyDefaults(); this.useDefaults = true; }
/// <summary> /// Writes the logging settings to the XmlWriter. /// </summary> /// <param name="writer">The writer to write to.</param> /// <param name="settings">The list of settings to write.</param> private void WriteLoggingSettings(XmlWriter writer, LogHandlerSetting[] settings) { if (logSettings.Count != 0) { writer.WriteStartElement("logging"); foreach (LogHandlerSetting setting in settings) { writer.WriteStartElement("loghandler"); setting.WriteXml(writer); writer.WriteEndElement(); } writer.WriteEndElement(); } }
/// <summary> /// Reads the logging settings. /// </summary> /// <param name="reader">The reader to read from.</param> private void ReadLoggingSettings(XmlReader reader) { LogHandlerSetting logHandler; reader.Read(); while (true) { switch (reader.NodeType) { case XmlNodeType.Element: if (reader.Name == "loghandler") { logHandler = new LogHandlerSetting(string.Empty); logHandler.ReadXml(reader); LogSettings.Add(logHandler); } else reader.Skip(); break; case XmlNodeType.EndElement: reader.Read(); return; default: if (!reader.Read()) { return; } break; } } }
/// <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(); }
/// <summary> /// Initializes a new instance of the ChannelFilter class. /// </summary> /// <param name="channel">The name of the channel, this filter applys to.</param> /// <param name="defaults">The setting base, this filter belongs to.</param> /// <param name="filter">The filter used for this channel.</param> internal ChannelFilter(string channel, LogHandlerSetting defaults, string filter) { channelName = channel; defaultFilter = defaults; ParseFilter(filter); }