示例#1
0
 protected entry_text_reader_base(log_settings_string sett) : base(sett)
 {
     util.postpone(() => new Thread(read_entries_thread)
     {
         IsBackground = true
     }.Start(), 1);
 }
示例#2
0
 public void merge(log_settings_string other_sett)
 {
     // note: i set it like this, so that in case of any change, I call the on_change delegate
     foreach (var name in other_sett.settings_.names())
     {
         settings_.set(name, other_sett.settings_.get(name));
     }
 }
示例#3
0
        private void load_save(bool load, string prefix)
        {
            app.load_save(load, ref name, prefix + ".name", "Default");

            string settings_str = default_settings_.ToString();

            if (load)
            {
                app.load_save(load, ref settings_str, prefix + ".default_settings");
                default_settings_ = new log_settings_string(settings_str);

                if (settings_str == "")
                {
                    // ... 1.4.8- kept the old name for persistenting
                    app.load_save(load, ref settings_str, prefix + ".default_syntax");
                    if (settings_str != "")
                    {
                        default_settings_.syntax.set(settings_str);
                    }
                }
            }
            else
            {
                app.load_save(load, ref settings_str, prefix + ".default_settings");
            }

            int view_count = views.Count;

            app.load_save(load, ref view_count, prefix + ".view_count", 0);
            if (load)
            {
                views.Clear();
                while (views.Count < view_count)
                {
                    views.Add(new ui_view());
                }
            }

            for (int i = 0; i < view_count; ++i)
            {
                views[i].load_save(load, prefix + ".view" + i + ".");
            }

            if (load && views.Count == 0)
            {
                views.Add(new ui_view()
                {
                    is_default_name = true, name = "View_1"
                });
            }
        }
示例#4
0
        // reads the config file, and sets as many settings as possible
        //
        public static log_settings_string load_config_file(string config_file)
        {
            log_settings_string config = new log_settings_string("");

            try {
                var doc = new XmlDocument();
                using (var sr = new StringReader(File.ReadAllText(config_file)))
                    using (var xtr = new XmlTextReader(sr)
                    {
                        Namespaces = false
                    })
                        doc.Load(xtr);

                var root    = doc.DocumentElement;
                var log4net = root.SelectSingleNode("//log4net");
                var nlog    = root.SelectSingleNode("//nlog");
                if (root.Name == "log4net")
                {
                    log4net = root;
                }
                else if (root.Name == "nlog")
                {
                    nlog = root;
                }

                if (log4net != null)
                {
                    parse_log4net_config_file(log4net, config_file, config);
                }
                else if (nlog != null)
                {
                    parse_nlog_config_file(nlog, config_file, config);
                }
            } catch (Exception e) {
                logger.Error("can't read config file " + config_file + " : " + e.Message);
            }
            return(config);
        }
        public file_text_reader(log_settings_string sett) : base(sett)
        {
            string file = sett.name;

            buffer_ = new byte[max_read_in_one_go];
            try {
                // get absolute path - normally, this should be the absolute path, but just to be sure
                file_ = new FileInfo(file).FullName;
            } catch {
                file_ = file;
            }

            var thread = app.inst.use_file_monitoring_api ? new Thread(read_all_file_thread_file_monitoring_api)
            {
                IsBackground = true
            }
                                                          : new Thread(read_all_file_thread)
            {
                IsBackground = true
            };

            thread.Start();
        }
示例#6
0
        private static void parse_log4net_config_file(XmlNode log4net_root, string config_file, log_settings_string config)
        {
            string dir       = new FileInfo(config_file).DirectoryName;
            var    appenders = log4net_root.SelectNodes(".//appender");

            foreach (XmlNode appender in appenders)
            {
                var appender_type = appender.Attributes["type"].Value.ToLower();
                if (appender_type.Contains("file"))
                {
                    // it's a file
                    var file = appender.SelectSingleNode("./file");
                    if (file != null)
                    {
                        string file_name = file.Attributes["value"].Value.Trim();
                        if (file_name.StartsWith("${"))
                        {
                            file_name = file_name.Substring(file_name.IndexOf("}") + 1);
                        }
                        if (file_name.StartsWith("\\"))
                        {
                            file_name = file_name.Substring(1);
                        }

                        if (!Path.IsPathRooted(file_name))
                        {
                            file_name = dir + "//" + file_name;
                        }

                        config.type.set(log_type.file);
                        config.name.set(file_name);
                        // force recomputing the syntax (in case it was already found)
                        config.syntax.set(file_text_reader.UNKNOWN_SYNTAX);
                    }
                }
                else if (appender_type.Contains("adonet"))
                {
                    // database
                    var type = appender.SelectSingleNode("./connectionType");
                    var connection_string = appender.SelectSingleNode("./connectionString");
                    var cmd_text          = appender.SelectSingleNode("./commandText");
                    if (type != null)
                    {
                        var db_type = type.Attributes["value"].Value;
                        // if we already have the configuration set, it means that we have a file as well - we prefer the file
                        if (config.name == "")
                        {
                            config.type.set(log_type.db);
                        }
                        config.db_provider.set(db_util.db_connection_type_to_db_provider(db_type));
                        config.db_connection_string.set(connection_string.Attributes["value"].Value);

                        if (cmd_text != null)
                        {
                            string sql = cmd_text.Attributes["value"].Value.ToLower().Trim();
                            if (sql.StartsWith("insert into"))
                            {
                                var fields = db_util.insert_into_to_db_fields(sql);
                                if (fields.Count > 0)
                                {
                                    config.db_fields.set(util.concatenate(fields, "\r\n"));
                                }
                                sql = sql.Substring(11).Trim();
                                int separator = sql.IndexOf("(");
                                if (separator > 0)
                                {
                                    string table_name = sql.Substring(0, separator).Trim();
                                    config.db_table_name.set(table_name);
                                }
                            }
                        }
                    }
                }

                // find out pattern (syntax)
                bool syntax_found = config.syntax != file_text_reader.UNKNOWN_SYNTAX;
                if (!syntax_found)
                {
                    var pattern = appender.SelectSingleNode("./conversionpattern");
                    var layout  = appender.SelectSingleNode("./layout");
                    if (pattern != null)
                    {
                        var value = layout.Attributes["value"].Value;
                        if (value != null)
                        {
                            config.syntax.set(value);
                        }
                    }
                    else if (layout != null)
                    {
                        var value = layout.Attributes["value"].Value;
                        if (value != null)
                        {
                            // here, the value might be for a non-standard layout - so, try to actually parse it
                            var parsed = parse_log4net_syntax.parse(value);
                            if (parsed != "")
                            {
                                config.syntax.set(value);
                            }
                        }
                    }
                }
            }
        }
示例#7
0
        private static void parse_nlog_config_file(XmlNode nlog_root, string config_file, log_settings_string config)
        {
            string dir       = new FileInfo(config_file).DirectoryName;
            var    appenders = nlog_root.SelectNodes(".//target");

            foreach (XmlNode appender in appenders)
            {
                var appender_type = attribute_ending_with(appender, "type").Value.ToLower();
                if (appender_type.Contains("file"))
                {
                    var file_name = appender.Attributes["fileName"].Value;
                    if (file_name.StartsWith("${"))
                    {
                        file_name = file_name.Substring(file_name.IndexOf("}") + 1);
                    }
                    if (file_name.StartsWith("\\") || file_name.StartsWith("/"))
                    {
                        file_name = file_name.Substring(1);
                    }

                    if (!Path.IsPathRooted(file_name))
                    {
                        file_name = dir + "//" + file_name;
                    }

                    config.type.set(log_type.file);
                    config.name.set(file_name);

                    var layout = attribute_ending_with(appender, "layout");
                    if (layout != null)
                    {
                        var layout_str = layout.Value;
                        config.syntax.set(layout_str);
                    }
                }
                else if (appender_type.Contains("database"))
                {
                    var db_type           = appender.Attributes["dbProvider"].Value;
                    var connection_string = appender.Attributes["connectionString"].Value;
                    var cmd_text          = appender.Attributes["commandText"];
                    // if we already have the configuration set, it means that we have a file as well - we prefer the file
                    if (config.name == "")
                    {
                        config.type.set(log_type.db);
                    }
                    config.db_provider.set(db_util.db_connection_type_to_db_provider(db_type));
                    config.db_connection_string.set(connection_string);
                    if (cmd_text != null)
                    {
                        string sql = cmd_text.Value.ToLower().Trim();
                        if (sql.StartsWith("insert into"))
                        {
                            var fields = db_util.insert_into_to_db_fields(sql);
                            if (fields.Count > 0)
                            {
                                config.db_fields.set(util.concatenate(fields, "\r\n"));
                            }
                            sql = sql.Substring(11).Trim();
                            int separator = sql.IndexOf("(");
                            if (separator > 0)
                            {
                                string table_name = sql.Substring(0, separator).Trim();
                                config.db_table_name.set(table_name);
                            }
                        }
                    }
                }
            }
        }
示例#8
0
 protected text_reader(log_settings_string sett)
 {
     settings_             = sett;
     settings_.on_changed += on_settings_changed;
     on_settings_changed("");
 }
示例#9
0
 public void copy_from(ui_context other)
 {
     default_settings_ = other.default_settings_;
     name  = other.name;
     views = other.views.ToList();
 }
示例#10
0
        public void merge(string other)
        {
            log_settings_string other_sett = new log_settings_string(other);

            merge(other_sett);
        }
示例#11
0
 public debug_text_reader(log_settings_string sett) : base(sett)
 {
     settings.on_changed += (a) => force_reload("setting changed " + a);
 }
示例#12
0
 public event_log_reader(log_settings_string sett) : base(sett)
 {
     settings.on_changed += on_settings_changed;
     sett.name.set(friendly_name);
 }
示例#13
0
 protected file_text_reader_base(log_settings_string sett) : base(sett)
 {
 }