示例#1
0
 public void Analyse(IDFile file)
 {
     lock (this)
     {
         _logger.LogInformation($"{file} 加入待处理队列");
         _queue.Enqueue(file);
         mre_addFile.Set();
     }
 }
        private async void CheckFile(IDFile file)
        {
            //判断一个文件是否需要处理等等

            _logger.LogDebug($"暂定所有的文件都处理");

            _logger.LogInformation($"{file} 的日志内容需要被处理");

            _fileChanged(file);
        }
示例#3
0
        private void AnyThresd()
        {
            Task.Run(() =>
            {
                IDFile file = null;

                while (true)
                {
                    lock (this)
                    {
                        if (_queue.Count > 0)
                        {
                            file = _queue.Dequeue();
                        }
                    }

                    if (file != null)
                    {
                        _logger.LogInformation($"开始处理 {file}");

                        using (var sr = new StreamReader(file.FullPath))
                        {
                            var line    = "";
                            var index   = 1;
                            var message = "";

                            var context = new CollectContext();

                            while ((line = sr.ReadLine()) != null)
                            {
                                if (!Regex.IsMatch(line, _options.Mulitline.Pattern))
                                {
                                    context.Fields["message"] = message;
                                    _dealContext(context);

                                    context = new CollectContext();
                                    index   = 1;
                                    message = "";

                                    context.Fields["path"]         = file.FullPath;
                                    context.Fields["basefilename"] = file.Name.Split('.')[0].ToLower();
                                }

                                line = line.TrimStart();

                                if (index <= _options.Mulitline.SpecialLines)
                                {
                                    context.Fields[$"line{index}"] = line;

                                    index++;
                                }
                                else
                                {
                                    message += line + "\r\n";
                                }

                                mre_pauseToStart.WaitOne();
                            }
                        }

                        _logger.LogInformation($"{file} 处理完成");
                    }

                    if (file == null)
                    {
                        mre_addFile.WaitOne();
                    }

                    file = null;
                }
            });
        }