Skip to content

Commit ebac843

Browse files
authored
Merge pull request #61 from bing-framework/dev_3.1
Dev 3.1
2 parents 6cffb34 + 85c1fc5 commit ebac843

File tree

23 files changed

+566
-91
lines changed

23 files changed

+566
-91
lines changed

framework/src/Bing.AspNetCore/Bing/AspNetCore/Extensions/Extensions.ServiceCollection.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,36 @@ public static void AddApiInterfaceService<TApiInterfaceService>(this IServiceCol
4545
/// <param name="services">服务集合</param>
4646
/// <param name="setupAction">配置操作</param>
4747
public static void AddRequestResponseLog(this IServiceCollection services, Action<RequestResponseLoggerOptions> setupAction)
48+
{
49+
AddRequestResponseLog<DefaultRequestResponseLogger, DefaultRequestResponseLogCreator>(services, setupAction);
50+
}
51+
52+
/// <summary>
53+
/// 注册请求响应日志服务
54+
/// </summary>
55+
/// <typeparam name="TLogger">请求响应日志记录器</typeparam>
56+
/// <param name="services">服务集合</param>
57+
/// <param name="setupAction">配置操作</param>
58+
public static void AddRequestResponseLog<TLogger>(this IServiceCollection services, Action<RequestResponseLoggerOptions> setupAction)
59+
where TLogger : class, IRequestResponseLogger
60+
{
61+
AddRequestResponseLog<TLogger, DefaultRequestResponseLogCreator>(services, setupAction);
62+
}
63+
64+
/// <summary>
65+
/// 注册请求响应日志服务
66+
/// </summary>
67+
/// <typeparam name="TLogger">请求响应日志记录器</typeparam>
68+
/// <typeparam name="TLogCreator">请求响应日志创建器</typeparam>
69+
/// <param name="services">服务集合</param>
70+
/// <param name="setupAction">配置操作</param>
71+
public static void AddRequestResponseLog<TLogger, TLogCreator>(this IServiceCollection services, Action<RequestResponseLoggerOptions> setupAction)
72+
where TLogger : class, IRequestResponseLogger
73+
where TLogCreator : class, IRequestResponseLogCreator
4874
{
4975
services.Configure(setupAction);
50-
services.AddSingleton<IRequestResponseLogger, DefaultRequestResponseLogger>();
51-
services.AddScoped<IRequestResponseLogCreator, DefaultRequestResponseLogCreator>();
76+
services.AddSingleton<IRequestResponseLogger, TLogger>();
77+
services.AddScoped<IRequestResponseLogCreator, TLogCreator>();
5278
}
5379
}
5480
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace Bing.Logging
4+
{
5+
/// <summary>
6+
/// 日志构建器
7+
/// </summary>
8+
public sealed class BingLoggingBuilder
9+
{
10+
/// <summary>
11+
/// 初始化一个<see cref="BingLoggingBuilder"/>类型的实例
12+
/// </summary>
13+
/// <param name="services">服务集合</param>
14+
public BingLoggingBuilder(IServiceCollection services)
15+
{
16+
Services = services;
17+
}
18+
19+
/// <summary>
20+
/// 服务集合
21+
/// </summary>
22+
public IServiceCollection Services { get; }
23+
}
24+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace Bing.Logging
5+
{
6+
/// <summary>
7+
/// Bing 日志选项配置
8+
/// </summary>
9+
public class BingLoggingOptions
10+
{
11+
/// <summary>
12+
/// 初始化一个<see cref="BingLoggingOptions"/>类型的实例
13+
/// </summary>
14+
public BingLoggingOptions()
15+
{
16+
ClearProviders = false;
17+
Extensions = new List<IBingLoggingOptionsExtension>();
18+
}
19+
20+
/// <summary>
21+
/// 日志选项扩展列表
22+
/// </summary>
23+
internal IList<IBingLoggingOptionsExtension> Extensions { get; }
24+
25+
/// <summary>
26+
/// 是否清空日志提供程序
27+
/// </summary>
28+
public bool ClearProviders { get; set; }
29+
30+
/// <summary>
31+
/// 注册扩展
32+
/// </summary>
33+
/// <param name="extension">日志选项配置扩展</param>
34+
public void RegisterExtension(IBingLoggingOptionsExtension extension)
35+
{
36+
if (extension == null)
37+
throw new ArgumentNullException(nameof(extension));
38+
Extensions.Add(extension);
39+
}
40+
}
41+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
3+
namespace Bing.Logging
4+
{
5+
/// <summary>
6+
/// Bing 日志选项配置扩展
7+
/// </summary>
8+
public interface IBingLoggingOptionsExtension
9+
{
10+
/// <summary>
11+
/// 注册子服务
12+
/// </summary>
13+
/// <param name="services">服务集合</param>
14+
void AddServices(IServiceCollection services);
15+
}
16+
}
Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using Bing.DependencyInjection;
32
using Microsoft.Extensions.Logging;
43

54
namespace Bing.Logging
@@ -8,45 +7,52 @@ namespace Bing.Logging
87
/// 日志操作
98
/// </summary>
109
/// <typeparam name="TCategoryName">日志类别</typeparam>
11-
public interface ILog<out TCategoryName> : ITransientDependency
10+
public interface ILog<out TCategoryName> : ILog
11+
{
12+
}
13+
14+
/// <summary>
15+
/// 日志操作
16+
/// </summary>
17+
public interface ILog
1218
{
1319
/// <summary>
1420
/// 设置日志事件标识
1521
/// </summary>
1622
/// <param name="eventId">日志事件标识</param>
17-
ILog<TCategoryName> EventId(EventId eventId);
23+
ILog EventId(EventId eventId);
1824

1925
/// <summary>
2026
/// 设置异常
2127
/// </summary>
2228
/// <param name="exception">异常</param>
23-
ILog<TCategoryName> Exception(Exception exception);
29+
ILog Exception(Exception exception);
2430

2531
/// <summary>
2632
/// 设置自定义扩展属性
2733
/// </summary>
2834
/// <param name="propertyName">属性名</param>
2935
/// <param name="propertyValue">属性值</param>
30-
ILog<TCategoryName> Property(string propertyName, string propertyValue);
36+
ILog Property(string propertyName, string propertyValue);
3137

3238
/// <summary>
3339
/// 设置标签
3440
/// </summary>
3541
/// <param name="tags">标签</param>
36-
ILog<TCategoryName> Tags(params string[] tags);
42+
ILog Tags(params string[] tags);
3743

3844
/// <summary>
3945
/// 设置日志状态对象
4046
/// </summary>
4147
/// <param name="state">状态对象</param>
42-
ILog<TCategoryName> State(object state);
48+
ILog State(object state);
4349

4450
/// <summary>
4551
/// 设置日志消息
4652
/// </summary>
4753
/// <param name="message">日志消息</param>
4854
/// <param name="args">日志消息参数</param>
49-
ILog<TCategoryName> Message(string message, params object[] args);
55+
ILog Message(string message, params object[] args);
5056

5157
/// <summary>
5258
/// 是否启用
@@ -65,31 +71,31 @@ public interface ILog<out TCategoryName> : ITransientDependency
6571
/// <summary>
6672
/// 写跟踪日志
6773
/// </summary>
68-
ILog<TCategoryName> LogTrace();
74+
ILog LogTrace();
6975

7076
/// <summary>
7177
/// 写调试日志
7278
/// </summary>
73-
ILog<TCategoryName> LogDebug();
79+
ILog LogDebug();
7480

7581
/// <summary>
7682
/// 写信息日志
7783
/// </summary>
78-
ILog<TCategoryName> LogInformation();
84+
ILog LogInformation();
7985

8086
/// <summary>
8187
/// 写警告日志
8288
/// </summary>
83-
ILog<TCategoryName> LogWarning();
89+
ILog LogWarning();
8490

8591
/// <summary>
8692
/// 写错误日志
8793
/// </summary>
88-
ILog<TCategoryName> LogError();
94+
ILog LogError();
8995

9096
/// <summary>
9197
/// 写致命日志
9298
/// </summary>
93-
ILog<TCategoryName> LogCritical();
99+
ILog LogCritical();
94100
}
95101
}

framework/src/Bing.Logging/Bing/Logging/ILogExtensions.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ public static class ILogExtensions
1010
/// <summary>
1111
/// 添加消息
1212
/// </summary>
13-
/// <typeparam name="TCategoryName">日志类别</typeparam>
1413
/// <param name="log">日志操作</param>
1514
/// <param name="message">消息</param>
1615
/// <param name="args">日志消息参数</param>
17-
public static ILog<TCategoryName> Append<TCategoryName>(this ILog<TCategoryName> log, string message, params object[] args)
16+
public static ILog Append(this ILog log, string message, params object[] args)
1817
{
1918
if (log is null)
2019
throw new ArgumentNullException(nameof(log));
@@ -25,12 +24,11 @@ public static ILog<TCategoryName> Append<TCategoryName>(this ILog<TCategoryName>
2524
/// <summary>
2625
/// 添加消息,当条件为true时
2726
/// </summary>
28-
/// <typeparam name="TCategoryName">日志类别</typeparam>
2927
/// <param name="log">日志操作</param>
3028
/// <param name="message">消息</param>
3129
/// <param name="condition">条件,值为true时,则添加消息</param>
3230
/// <param name="args">日志消息参数</param>
33-
public static ILog<TCategoryName> AppendIf<TCategoryName>(this ILog<TCategoryName> log, string message, bool condition, params object[] args)
31+
public static ILog AppendIf(this ILog log, string message, bool condition, params object[] args)
3432
{
3533
if (log is null)
3634
throw new ArgumentNullException(nameof(log));
@@ -42,11 +40,10 @@ public static ILog<TCategoryName> AppendIf<TCategoryName>(this ILog<TCategoryNam
4240
/// <summary>
4341
/// 添加消息并换行
4442
/// </summary>
45-
/// <typeparam name="TCategoryName">日志类别</typeparam>
4643
/// <param name="log">日志操作</param>
4744
/// <param name="message">消息</param>
4845
/// <param name="args">日志消息参数</param>
49-
public static ILog<TCategoryName> AppendLine<TCategoryName>(this ILog<TCategoryName> log, string message, params object[] args)
46+
public static ILog AppendLine(this ILog log, string message, params object[] args)
5047
{
5148
if (log is null)
5249
throw new ArgumentNullException(nameof(log));
@@ -58,13 +55,12 @@ public static ILog<TCategoryName> AppendLine<TCategoryName>(this ILog<TCategoryN
5855
/// <summary>
5956
/// 添加消息并换行,当条件为true时
6057
/// </summary>
61-
/// <typeparam name="TCategoryName">日志类别</typeparam>
6258
/// <param name="log">日志操作</param>
6359
/// <param name="message">消息</param>
6460
/// <param name="condition">条件,值为true时,则添加消息</param>
6561
/// <param name="args">日志消息参数</param>
6662
/// <returns></returns>
67-
public static ILog<TCategoryName> AppendLineIf<TCategoryName>(this ILog<TCategoryName> log, string message, bool condition, params object[] args)
63+
public static ILog AppendLineIf(this ILog log, string message, bool condition, params object[] args)
6864
{
6965
if (log is null)
7066
throw new ArgumentNullException(nameof(log));
@@ -79,9 +75,8 @@ public static ILog<TCategoryName> AppendLineIf<TCategoryName>(this ILog<TCategor
7975
/// <summary>
8076
/// 消息换行
8177
/// </summary>
82-
/// <typeparam name="TCategoryName">日志类别</typeparam>
8378
/// <param name="log">日志操作</param>
84-
public static ILog<TCategoryName> Line<TCategoryName>(this ILog<TCategoryName> log)
79+
public static ILog Line(this ILog log)
8580
{
8681
if (log is null)
8782
throw new ArgumentNullException(nameof(log));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
3+
namespace Bing.Logging
4+
{
5+
/// <summary>
6+
/// 日志操作工厂
7+
/// </summary>
8+
public interface ILogFactory
9+
{
10+
/// <summary>
11+
/// 创建日志操作
12+
/// </summary>
13+
/// <param name="categoryName">日志类别</param>
14+
ILog CreateLog(string categoryName);
15+
16+
/// <summary>
17+
/// 创建日志操作
18+
/// </summary>
19+
/// <param name="type">日志类别类型</param>
20+
ILog CreateLog(Type type);
21+
}
22+
}

framework/src/Bing.Logging/Bing/Logging/ILoggerWrapper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
using System;
2-
using Bing.DependencyInjection;
32
using Microsoft.Extensions.Logging;
43

54
namespace Bing.Logging
65
{
76
/// <summary>
87
/// 日志记录包装器
98
/// </summary>
10-
/// <typeparam name="TCategoryName">日志类别</typeparam>
11-
public interface ILoggerWrapper<out TCategoryName> : ITransientDependency
9+
public interface ILoggerWrapper
1210
{
1311
/// <summary>
1412
/// 是否启用

0 commit comments

Comments
 (0)