From 2cda267ceca5507df8e763d777affb488b50cc84 Mon Sep 17 00:00:00 2001 From: MonkSoul Date: Thu, 15 Sep 2022 16:25:58 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20=E6=B7=BB=E5=8A=A0=20`ILoggerFac?= =?UTF-8?q?tory`=20=E6=97=A5=E5=BF=97=E5=B7=A5=E5=8E=82=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E6=89=B9=E9=87=8F=E6=B7=BB=E5=8A=A0=E6=96=87=E4=BB=B6=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=8B=93=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/ILoggerFactoryExtensions.cs | 18 ++++++++++++++++++ .../Extensions/ILoggerFactoryExtensions.cs | 18 ++++++++++++++++++ handbook/docs/upgrade.mdx | 1 + 3 files changed, 37 insertions(+) diff --git a/framework/Furion.Pure/Logging/Extensions/ILoggerFactoryExtensions.cs b/framework/Furion.Pure/Logging/Extensions/ILoggerFactoryExtensions.cs index 0b23cf28bc..4fd18b27fb 100644 --- a/framework/Furion.Pure/Logging/Extensions/ILoggerFactoryExtensions.cs +++ b/framework/Furion.Pure/Logging/Extensions/ILoggerFactoryExtensions.cs @@ -45,6 +45,24 @@ public static class ILoggerFactoryExtensions return factory; } + /// + /// 添加文件日志记录器 + /// + /// 日志工厂 + /// 日志文件完整路径或文件名,推荐 .log 作为拓展名 + /// + /// + public static ILoggerFactory AddFile(this ILoggerFactory factory, string fileName, Action configure) + { + var options = new FileLoggerOptions(); + configure?.Invoke(options); + + // 添加文件日志记录器提供程序 + factory.AddProvider(new FileLoggerProvider(fileName, options)); + + return factory; + } + /// /// 添加文件日志记录器 /// diff --git a/framework/Furion/Logging/Extensions/ILoggerFactoryExtensions.cs b/framework/Furion/Logging/Extensions/ILoggerFactoryExtensions.cs index 0b23cf28bc..4fd18b27fb 100644 --- a/framework/Furion/Logging/Extensions/ILoggerFactoryExtensions.cs +++ b/framework/Furion/Logging/Extensions/ILoggerFactoryExtensions.cs @@ -45,6 +45,24 @@ public static class ILoggerFactoryExtensions return factory; } + /// + /// 添加文件日志记录器 + /// + /// 日志工厂 + /// 日志文件完整路径或文件名,推荐 .log 作为拓展名 + /// + /// + public static ILoggerFactory AddFile(this ILoggerFactory factory, string fileName, Action configure) + { + var options = new FileLoggerOptions(); + configure?.Invoke(options); + + // 添加文件日志记录器提供程序 + factory.AddProvider(new FileLoggerProvider(fileName, options)); + + return factory; + } + /// /// 添加文件日志记录器 /// diff --git a/handbook/docs/upgrade.mdx b/handbook/docs/upgrade.mdx index 510437845d..f9aada347c 100644 --- a/handbook/docs/upgrade.mdx +++ b/handbook/docs/upgrade.mdx @@ -39,6 +39,7 @@ import useBaseUrl from "@docusaurus/useBaseUrl"; - [新增] `DateOnlyJsonConverter` 和 `DateOnlyOffsetJsonConverter` 序列化转换器 [!565](https://gitee.com/dotnetchina/Furion/pulls/565) - [新增] 事件总线 `LogEnabled` 配置,可控制是否输出服务日志 [#I5QLY5](https://gitee.com/dotnetchina/Furion/issues/I5QLY5) - [新增] **可实现任何多套规范化结果功能,支持特定控制器,特定方法** [#I5QZ37](https://gitee.com/dotnetchina/Furion/issues/I5QZ37) + - [新增] `ILoggerFactory` 日志工厂动态批量添加文件日志拓展 [#I5R9PO](https://gitee.com/dotnetchina/Furion/issues/I5R9PO) - **突破性变化** -- Gitee