Пример #1
0
        private void ReadFile()
        {
            if (!File.Exists(_fileToWatch))
            {
                return;
            }

            //Factory pattern to decide which class object need to invoke for file parsing
            ParserFactory parseFact = new ParserFactory();
            IParser parser = parseFact.GetParser(ParserFactory.ParserFileEnums.Flat);

            StreamReader fileReader;
            using (fileReader = new StreamReader(new FileStream(_fileToWatch, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
            {
                if (fileReader.BaseStream.Length == _lastFileLength)
                    return;

                if (fileReader.BaseStream.Length < _lastFileLength)
                {
                    //Log file has been trucated/deleted/renamed
                    _lastFileLength = 0;
                }

                // Seek to the last file length
                fileReader.BaseStream.Seek(_lastFileLength, SeekOrigin.Begin);

                //Now decide which all parameters we need to pass to parse function
                //ConfigurationFactory configFact=new ConfigurationFactory();
                //IConfiguration config = configFact.GetConfiguration(ConfigurationFactory.ConfigurationFileEnums.FlatFile);
                ConfigurationSettings settings = new ConfigurationSettings();
                settings.ConversionPattern = ConversionPattern;
                settings.FileReader = fileReader;
                Log2Console.Configuration.Configuration config = new Log2Console.Configuration.Configuration();
                config.Configurations = settings;

                //At runtime call
                List<LogMessage> logMsgs = parser.Parse(config);//To parse flat file

                //Notify the UI with the set of messages
                Notifiable.Notify(logMsgs.ToArray());

                // Update the last file length
                _lastFileLength = fileReader.BaseStream.Position;
            }
        }
Пример #2
0
        /// <summary>
        /// To read data from database log table
        /// </summary>
        private void ReadLogTable()
        {
            //Factory pattern to decide which class object need to invoke for file parsing
            ParserFactory parseFact = new ParserFactory();
            IParser parser = parseFact.GetParser(ParserFactory.ParserFileEnums.SQL);

            //Now decide which all parameters we need to pass to parse function
            ConfigurationSettings settings = new ConfigurationSettings();
            settings.FieldList = _fieldList;
            settings.LogTableName = LogTableName;
            settings.ConnectionString = ConnectionString;
            settings.RowsCount = RowsCount;

            Log2Console.Configuration.Configuration config = new Log2Console.Configuration.Configuration();
            config.Configurations = settings;


            //At runtime call
            List<LogMessage> logMsgs = parser.Parse(config);


            // Notify the UI with the set of messages
            Notifiable.Notify(logMsgs.ToArray());
        }