Exemplo n.º 1
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginPath">The absolute path to the plugin dll.</param>
        /// <param name="ircConfig">The IRC config we are using.</param>
        public void Init(string pluginPath, IIrcConfig ircConfig)
        {
            string pluginDir = Path.GetDirectoryName(pluginPath);

            IrcLoggerConfig config = XmlLoader.LoadIrcLoggerConfig(
                Path.Combine(pluginDir, "IrcLoggerConfig.xml")
                );

            if (string.IsNullOrEmpty(config.LogFileLocation))
            {
                config.LogFileLocation = Path.Combine(pluginDir, "Logs");
            }
            if (string.IsNullOrEmpty(config.LogName))
            {
                config.LogName = "irclog";
            }

            this.logManager = new LogManager(config);

            AllHandler handler = new AllHandler(
                this.HandleLogEvent
                );

            this.handlers.Add(handler);
        }
Exemplo n.º 2
0
        // -------- Constructor --------

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="config">The config to use.</param>
        public LogManager(IrcLoggerConfig config)
        {
            ArgumentChecker.IsNotNull(config, nameof(config));

            this.config           = config;
            this.currentLineCount = 0;
            this.CurrentFileName  = string.Empty;
            this.LastFileName     = string.Empty;

            if (Directory.Exists(config.LogFileLocation) == false)
            {
                Directory.CreateDirectory(config.LogFileLocation);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Loads the irc logger config from the given xml file.
        /// </summary>
        /// <param name="xmlFilePath">The file name to load.</param>
        /// <returns>An Irc Logger config object from the given xml file.</returns>
        public static IrcLoggerConfig LoadIrcLoggerConfig(string xmlFilePath)
        {
            if (File.Exists(xmlFilePath) == false)
            {
                throw new FileNotFoundException("Could not find irc logger plugin config file " + xmlFilePath);
            }

            XmlDocument doc = new XmlDocument();

            doc.Load(xmlFilePath);

            XmlElement rootNode = doc.DocumentElement;

            if (rootNode.Name != ircloggerRootNodeName)
            {
                throw new XmlException(
                          "Root XML node should be named \"" + ircloggerRootNodeName + "\".  Got: " + rootNode.Name
                          );
            }

            IrcLoggerConfig config = new IrcLoggerConfig();

            foreach (XmlNode childNode in rootNode.ChildNodes)
            {
                switch (childNode.Name)
                {
                case "logfilelocation":
                    config.LogFileLocation = childNode.InnerText;
                    break;

                case "maxnumbermessagesperlog":
                    if (string.IsNullOrEmpty(childNode.InnerText) == false)
                    {
                        config.MaxNumberMessagesPerLog = uint.Parse(childNode.InnerText);
                    }
                    // Else, empty string results in default value.
                    break;

                case "logname":
                    config.LogName = childNode.InnerText;
                    break;
                }
            }

            return(config);
        }
Exemplo n.º 4
0
        // -------- Functions --------

        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="pluginInit">The class that has information required for initing the plugin.</param>
        public void Init(PluginInitor initor)
        {
            string pluginDir = Path.Combine(
                initor.ChaskisConfigPluginRoot,
                "IrcLogger"
                );

            string configPath = Path.Combine(
                pluginDir,
                "IrcLoggerConfig.xml"
                );

            this.config = XmlLoader.LoadIrcLoggerConfig(
                configPath
                );

            if (string.IsNullOrEmpty(config.LogFileLocation))
            {
                config.LogFileLocation = Path.Combine(pluginDir, "Logs");
            }
            if (string.IsNullOrEmpty(config.LogName))
            {
                config.LogName = "irclog";
            }

            this.logManager = new LogManager(config, initor.Log);

            AllHandlerConfig allHandlerConfig = new AllHandlerConfig
            {
                AllAction = this.HandleLogEvent
            };

            AllHandler handler = new AllHandler(
                allHandlerConfig
                );

            this.handlers.Add(handler);
        }
Exemplo n.º 5
0
        // -------- Constructor --------

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="config">The config to use.</param>
        /// <param name="statusLog">The log to use for reporting status.</param>
        public LogManager(IrcLoggerConfig config, GenericLogger statusLog)
        {
            ArgumentChecker.IsNotNull(config, nameof(config));

            this.config           = config;
            this.currentLineCount = 0;
            this.CurrentFileName  = string.Empty;
            this.LastFileName     = string.Empty;

            if (Directory.Exists(config.LogFileLocation) == false)
            {
                Directory.CreateDirectory(config.LogFileLocation);
            }

            this.statusLog = statusLog;

            this.writerThread = new EventExecutor("IRC Logger");

            this.writerThread.OnError += WriterThread_OnError;

            this.writerThread.Start();
            this.isDisposed = false;
        }