示例#1
0
 public Monitor(LogFileMonitor l)
 {
     logMonitor = l;
     logMonitor.ChangedLogMessage += this.parse;
     channel = l.FileChannel.Channel.ChannelName;
     logMonitor.Refresh(true);
 }
示例#2
0
        public List <LogFileMonitor> ReadDirectory()
        {
            List <LogFileMonitor> monitors = new List <LogFileMonitor>();

            DirectoryInfo dir = new DirectoryInfo(Path);

            if (dir.Exists)
            {
                FileInfo[] files = dir.GetFiles(watch.Filter);

                files = files.OrderByDescending(x => x.LastWriteTime).ToArray <FileInfo>();

                foreach (FileInfo file in files)
                {
                    file.Refresh();
                    // only read log files that have been updated in the last 2 hours
                    if (file.LastWriteTime >= DateTime.Now.AddSeconds(-ReadLogsAferSeconds))
                    {
                        LogFileMonitor lfm = GetFileItem(file.FullName);
                        lfm.Refresh(true);

                        Boolean dupe = false;
                        foreach (LogFileMonitor m in monitors)
                        {
                            if (m.FileChannel.Channel.ChannelName == lfm.FileChannel.Channel.ChannelName)
                            {
                                dupe = true;
                                if (m.FileChannel.File.LastWriteTime < lfm.FileChannel.File.LastWriteTime)
                                {
                                    monitors.Remove(m);
                                    monitors.Add(m);
                                }
                                break;
                            }
                        }
                        if (!dupe)
                        {
                            monitors.Add(lfm);
                        }
                    }
                }
            }

            return(monitors);
        }
示例#3
0
        private LogFileMonitor GetFileItem(string FullPath)
        {
            FileInfo       fileInfo = new FileInfo(FullPath);
            LogFileMonitor monitor;

            lock (fileSteams)
            {
                if (fileSteams.ContainsKey(FullPath))
                {
                    monitor = fileSteams[FullPath];
                }
                else
                {
                    fileSteams[FullPath] = new LogFileMonitor(fileInfo);
                }

                return(fileSteams[FullPath]);
            }
        }
示例#4
0
 private void OnChanged(object source, FileSystemEventArgs e)
 {
     LogFileMonitor monitor = GetFileItem(e.FullPath);
 }
示例#5
0
        private LogFileMonitor GetFileItem(string FullPath)
        {
            FileInfo fileInfo = new FileInfo(FullPath);
            LogFileMonitor monitor;

            lock (fileSteams)
            {
                if (fileSteams.ContainsKey(FullPath))
                {
                    monitor = fileSteams[FullPath];
                }
                else
                {
                    fileSteams[FullPath] = new LogFileMonitor(fileInfo);
                }

                return fileSteams[FullPath];
            }
        }
示例#6
0
 public Monitor(LogFileMonitor l)
 {
     logMonitor = l;
     logMonitor.ChangedLogMessage += this.parse;
     channel = l.FileChannel.Channel.ChannelName;
     logMonitor.Refresh(true);
 }