[fix]修正UdpServer在接收广播时连续启动接收的错误,在StarAgent中,此时可能收到广播包,SocketFlags是Broadcast,需要清空,否则报错“参考的对象类型不支持尝试的操作”; 无需设置SocketOptionName.PacketInformation,在ReceiveMessageFromAsync时会自动设置,并且支持ipv6;
石头 编写于 2024-10-10 00:36:00 石头 提交于 2024-10-10 00:45:43
X
namespace NewLife.Log;

/// <summary>等级日志提供者,不同等级分不同日志输出</summary>
public class LevelLog : Logger
{
    private IDictionary<LogLevel, ILog> _logs = new Dictionary<LogLevel, ILog>();

    /// <summary>通过指定路径和文件格式来实例化等级日志,每个等级使用自己的日志输出</summary>
    /// <param name="logPath"></param>
    /// <param name="fileFormat"></param>
    public LevelLog(String logPath, String fileFormat)
    {
        foreach (var item in Enum.GetValues(typeof(LogLevel)))
        {
            if (item is LogLevel level && level is > LogLevel.All and < LogLevel.Off)
            {
                _logs[level] = new TextFileLog(logPath, false, fileFormat) { Level = level };
            }
        }
    }

    /// <summary>写日志</summary>
    /// <param name="level"></param>
    /// <param name="format"></param>
    /// <param name="args"></param>
    protected override void OnWrite(LogLevel level, String format, params Object?[] args)
    {
        if (_logs.TryGetValue(level, out var log)) log.Write(level, format, args);
    }
}