Files
ThingsGateway/src/Admin/ThingsGateway.Furion/Logging/Implantations/Empty/EmptyLoggerProvider.cs
2248356998 qq.com b989aa5561 10.6.21
2025-05-26 00:05:16 +08:00

54 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ------------------------------------------------------------------------
// 版权信息
// 版权归百小僧及百签科技(广东)有限公司所有。
// 所有权利保留。
// 官方网站https://baiqian.com
//
// 许可证信息
// 项目主要遵循 MIT 许可证和 Apache 许可证(版本 2.0)进行分发和使用。
// 许可证的完整文本可以在源代码树根目录中的 LICENSE-APACHE 和 LICENSE-MIT 文件中找到。
// ------------------------------------------------------------------------
using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;
using ThingsGateway.Extension.Generic;
namespace ThingsGateway.Logging;
/// <summary>
/// 空日志记录器提供程序
/// </summary>
/// <remarks>https://docs.microsoft.com/zh-cn/dotnet/core/extensions/custom-logging-provider</remarks>
[SuppressSniffer, ProviderAlias("Empty")]
public sealed class EmptyLoggerProvider : ILoggerProvider
{
/// <summary>
/// 存储多日志分类日志记录器
/// </summary>
private readonly ConcurrentDictionary<string, EmptyLogger> _emptyLoggers = new();
/// <summary>
/// 创建空日志记录器
/// </summary>
/// <param name="categoryName">日志分类名</param>
/// <returns><see cref="ILogger"/></returns>
public ILogger CreateLogger(string categoryName)
{
return _emptyLoggers.GetOrAdd(categoryName, name => new EmptyLogger(categoryName, this));
}
public void RemoveCache(string categoryName)
{
_emptyLoggers.Remove(categoryName);
}
/// <summary>
/// 释放非托管资源
/// </summary>
/// <remarks>控制日志消息队列</remarks>
public void Dispose()
{
// 清空空日志记录器
_emptyLoggers.Clear();
}
}