log日志,序数文件,控制文件size. 可改装为httpri日志 post log C#

这个博客介绍了一个C#的日志管理类库,用于记录INFO、DEBUG、ERROR等不同级别的日志,并通过检查文件大小来创建新的日志文件,确保文件不超过指定大小。同时,使用了并发控制来保证日志写入的安全性。
摘要由CSDN通过智能技术生成

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using static Common.CommonBase;

namespace Common
{
    public class Logger
    {
        public LoggerMode loggerMode { get; set; } = LoggerMode.INFO;
        public string LoggerLine { get; set; } = string.Empty;
    }
    public class LoggerQueueHelper
    {
        private LoggerQueueHelper()
        { 
        } 
        private static string _LogPath;
        public static string LogPath
        {
            get
            {
                if (MemoryCacheHelper.Contains("LogPath") == false)
                {
                    DateTimeOffset thisOffsetTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,23,59,59);
                    string logPath = Path.GetFullPath("./"); 
                    MemoryCacheHelper.Set("LogPath", logPath, thisOffsetTime);
                    string path1 = logPath;
                    if (!Directory.Exists(path1))
                    {
                        Directory.CreateDirectory(path1);
                    }
                    _LogPath = logPath;
                }
                else
                {
                    _LogPath = MemoryCacheHelper.GetCacheItem<string>("LogPath");
                }
                return _LogPath;
            }
        }
        #region  
        private static object lockObj1 = new object();
        private static void Log(Logger logger)
        {
            lock (lockObj1)
            {
                string filePath = Path.Combine(LogPath, "log");
                str

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值