src/ZKEACMS.SpiderLog/Models/LogWritter.cs

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

/* http://www.zkea.net/ 
 * Copyright (c) ZKEASOFT. All rights reserved. 
 * http://www.zkea.net/licenses */

using Easy.Extend;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZKEACMS.SpiderLog.Models
{
    public class LogWritter : IDisposable
    {
        private const long MaxFileSize = 2048576;
        private StreamWriter _writer;
        private int writeCount = 0;
        public LogWritter(string filePath)
        {
            LogFileInfo = new FileInfo(filePath);
            FilePath = filePath;
            CreateWriter();
        }
        private void CreateWriter()
        {
            bool append = LogFileSize < MaxFileSize;
            if (!LogFileInfo.Directory.Exists)
            {
                LogFileInfo.Directory.Create();
            }
            _writer = new StreamWriter(FilePath, append, Encoding.UTF8);
        }
        private void NewWriter()
        {
            if (_writer != null)
            {
                _writer.Close();
                _writer.Dispose();
            }
            LogFileInfo.Refresh();
            CreateWriter();
        }
        public long LogFileSize
        {
            get
            {
                if (LogFileInfo.Exists) return LogFileInfo.Length;

                return 0;
            }
        }
        public FileInfo LogFileInfo { get; set; }
        public string FilePath { get; set; }

        public void WriteLog(string log)
        {
            writeCount += 1;

后面还有 13 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。