Exemplo n.º 1
0
        public void WriteLogFile(string format)
        {
            _lockSlim.EnterWriteLock();

            try
            {
                _dir = SubDirOp.NextDir(_baseDir, _dir);
                var cur = Path.Combine(_dir, _fn);
                if (FileBakOp.NextFile(new FileInfo(cur)))
                {
                    cur = FileBakOp.NextFileName;
                }
                //using (var fs = finfo.Open(FileMode.Open, FileAccess.Write))
                using (var fs = File.Open(cur, FileMode.OpenOrCreate, FileAccess.Write))
                {
                    using (var sw = new StreamWriter(fs, _encoding))
                    {
                        sw.BaseStream.Seek(0, SeekOrigin.End);
                        sw.Write($"{format}");
                        sw.WriteLine();
                        sw.Flush();
                    }
                }
            }
            catch (Exception e)
            {
                //ignore
            }
            _lockSlim.ExitWriteLock();
        }
Exemplo n.º 2
0
 public TxtSimpLog(Encoding encoding)
 {
     _encoding = encoding;
     _baseDir  = @".\";
     SubDirOp  = new SubDirOp();
     FileBakOp = new FileBakOp();
     _fn       = "simplog.txt";
 }
Exemplo n.º 3
0
 public CsvSummary(Encoding encoding)
 {
     _encoding    = encoding;
     SubDirOp     = new SubDirOp();
     FileBakOp    = new FileBakOp();
     BaseDir      = @".\";
     _dir         = BaseDir;
     FileName     = "tst.csv";
     _curFileName = FileName;
 }
Exemplo n.º 4
0
        public void AppendResultInfo(object resultInfo)
        {
            _lockSlim.EnterWriteLock();

            try
            {
                _dir = SubDirOp.NextDir(_baseDir, _dir);

                var cur = Path.Combine(_dir, _fn);

                Action <CsvFileWriter, object> act = null;

                if (FileBakOp.NextFile(new FileInfo(cur)))
                {
                    _curFileName = FileBakOp.NextFileName;
                    act          = InitHeraders;
                }

                using (var fs = File.Open(_curFileName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
                {
                    fs.Seek(0, SeekOrigin.End);
                    using (var csv = new CsvFileWriter(fs, _encoding))
                    {
                        var csr = ResultInfoToCsvRow(resultInfo);
                        if (csr != null)
                        {
                            act?.Invoke(csv, resultInfo);
                            csv.WriteRow(csr);
                            csv.Flush();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //ignore
            }

            _lockSlim.ExitWriteLock();
        }