Skip to content

Commit 82de9a6

Browse files
committed
feat: 新增日志模块
1 parent 0440cfd commit 82de9a6

File tree

14 files changed

+749
-4
lines changed

14 files changed

+749
-4
lines changed

Bing.All.sln

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.AspNetCore.Authenticat
220220
EndProject
221221
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TextTemplating", "TextTemplating", "{09A94120-CE45-402F-B45A-21DF04F0C226}"
222222
EndProject
223-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.TextTemplating", "framework\src\Bing.TextTemplating\Bing.TextTemplating.csproj", "{E06DC786-72AB-417B-ACDB-AF00688544EA}"
223+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.TextTemplating", "framework\src\Bing.TextTemplating\Bing.TextTemplating.csproj", "{E06DC786-72AB-417B-ACDB-AF00688544EA}"
224224
EndProject
225-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.TextTemplating.Scriban", "framework\src\Bing.TextTemplating.Scriban\Bing.TextTemplating.Scriban.csproj", "{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83}"
225+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.TextTemplating.Scriban", "framework\src\Bing.TextTemplating.Scriban\Bing.TextTemplating.Scriban.csproj", "{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83}"
226226
EndProject
227-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Test.Shared", "framework\tests\Bing.Test.Shared\Bing.Test.Shared.csproj", "{D6C96AE5-8756-4278-A331-43073E08C3ED}"
227+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Test.Shared", "framework\tests\Bing.Test.Shared\Bing.Test.Shared.csproj", "{D6C96AE5-8756-4278-A331-43073E08C3ED}"
228228
EndProject
229-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Ddd.Domain.Tests", "framework\tests\Bing.Ddd.Domain.Tests\Bing.Ddd.Domain.Tests.csproj", "{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}"
229+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bing.Ddd.Domain.Tests", "framework\tests\Bing.Ddd.Domain.Tests\Bing.Ddd.Domain.Tests.csproj", "{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}"
230+
EndProject
231+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Logging", "framework\src\Bing.Logging\Bing.Logging.csproj", "{ECB340A3-A21C-460D-8EBC-09EA5FB8731C}"
232+
EndProject
233+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bing.Logging.Sinks.Exceptionless", "framework\src\Bing.Logging.Sinks.Exceptionless\Bing.Logging.Sinks.Exceptionless.csproj", "{04EB5533-6885-4292-BED1-4D06A5E162D1}"
230234
EndProject
231235
Global
232236
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -510,6 +514,14 @@ Global
510514
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Debug|Any CPU.Build.0 = Debug|Any CPU
511515
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Release|Any CPU.ActiveCfg = Release|Any CPU
512516
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94}.Release|Any CPU.Build.0 = Release|Any CPU
517+
{ECB340A3-A21C-460D-8EBC-09EA5FB8731C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
518+
{ECB340A3-A21C-460D-8EBC-09EA5FB8731C}.Debug|Any CPU.Build.0 = Debug|Any CPU
519+
{ECB340A3-A21C-460D-8EBC-09EA5FB8731C}.Release|Any CPU.ActiveCfg = Release|Any CPU
520+
{ECB340A3-A21C-460D-8EBC-09EA5FB8731C}.Release|Any CPU.Build.0 = Release|Any CPU
521+
{04EB5533-6885-4292-BED1-4D06A5E162D1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
522+
{04EB5533-6885-4292-BED1-4D06A5E162D1}.Debug|Any CPU.Build.0 = Debug|Any CPU
523+
{04EB5533-6885-4292-BED1-4D06A5E162D1}.Release|Any CPU.ActiveCfg = Release|Any CPU
524+
{04EB5533-6885-4292-BED1-4D06A5E162D1}.Release|Any CPU.Build.0 = Release|Any CPU
513525
EndGlobalSection
514526
GlobalSection(SolutionProperties) = preSolution
515527
HideSolutionNode = FALSE
@@ -610,6 +622,8 @@ Global
610622
{65B439C9-4B54-4DB8-86B3-9EBE8E62DF83} = {09A94120-CE45-402F-B45A-21DF04F0C226}
611623
{D6C96AE5-8756-4278-A331-43073E08C3ED} = {5C7976B4-C243-41B9-8303-8E8FAE099D31}
612624
{8B581529-D7D2-4DCF-824A-2AAFB58F8C94} = {5C7976B4-C243-41B9-8303-8E8FAE099D31}
625+
{ECB340A3-A21C-460D-8EBC-09EA5FB8731C} = {33F6CAB3-FD8A-4B91-9B94-A1E2DBC2759B}
626+
{04EB5533-6885-4292-BED1-4D06A5E162D1} = {33F6CAB3-FD8A-4B91-9B94-A1E2DBC2759B}
613627
EndGlobalSection
614628
GlobalSection(ExtensibilityGlobals) = postSolution
615629
SolutionGuid = {C1202A0F-83CC-4602-BCE5-20CB640BCAD4}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="project.props" />
3+
4+
<Import Project="project.dependency.props" />
5+
6+
<Import Project="..\..\..\framework.props" />
7+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace Bing.Logging.Sinks.Exceptionless.Internals
2+
{
3+
/// <summary>
4+
/// 日志级别切换器
5+
/// </summary>
6+
internal static class LogLevelSwitcher
7+
{
8+
/// <summary>
9+
/// 转换日志级别
10+
/// </summary>
11+
/// <param name="level">MS日志级别</param>
12+
public static global::Exceptionless.Logging.LogLevel Switch(Microsoft.Extensions.Logging.LogLevel level)
13+
{
14+
return level switch
15+
{
16+
Microsoft.Extensions.Logging.LogLevel.Trace => global::Exceptionless.Logging.LogLevel.Trace,
17+
Microsoft.Extensions.Logging.LogLevel.Debug => global::Exceptionless.Logging.LogLevel.Debug,
18+
Microsoft.Extensions.Logging.LogLevel.Information => global::Exceptionless.Logging.LogLevel.Info,
19+
Microsoft.Extensions.Logging.LogLevel.Warning => global::Exceptionless.Logging.LogLevel.Warn,
20+
Microsoft.Extensions.Logging.LogLevel.Error => global::Exceptionless.Logging.LogLevel.Error,
21+
Microsoft.Extensions.Logging.LogLevel.Critical => global::Exceptionless.Logging.LogLevel.Fatal,
22+
Microsoft.Extensions.Logging.LogLevel.None => global::Exceptionless.Logging.LogLevel.Off,
23+
_ => global::Exceptionless.Logging.LogLevel.Off
24+
};
25+
}
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
<ItemGroup>
3+
<ProjectReference Include="..\Bing.Logging\Bing.Logging.csproj" />
4+
</ItemGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="Exceptionless.Extensions.Hosting" Version="4.6.2" />
8+
<PackageReference Include="Exceptionless.Extensions.Logging" Version="4.6.2" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<PropertyGroup>
3+
<AssemblyName>Bing.Logging.Sinks.Exceptionless</AssemblyName>
4+
<PackageId>Bing.Logging.Sinks.Exceptionless</PackageId>
5+
<Description>Bing.Logging.Sinks.Exceptionless是Bing应用框架的Exceptionless日志操作类库。</Description>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="project.props" />
3+
4+
<Import Project="project.dependency.props" />
5+
6+
<Import Project="..\..\..\framework.props" />
7+
8+
</Project>
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Bing.Logging
5+
{
6+
/// <summary>
7+
/// 日志操作
8+
/// </summary>
9+
/// <typeparam name="TCategoryName">日志类别</typeparam>
10+
public interface ILog<out TCategoryName>
11+
{
12+
/// <summary>
13+
/// 设置日志事件标识
14+
/// </summary>
15+
/// <param name="eventId">日志事件标识</param>
16+
ILog<TCategoryName> EventId(EventId eventId);
17+
18+
/// <summary>
19+
/// 设置异常
20+
/// </summary>
21+
/// <param name="exception">异常</param>
22+
ILog<TCategoryName> Exception(Exception exception);
23+
24+
/// <summary>
25+
/// 设置自定义扩展属性
26+
/// </summary>
27+
/// <param name="propertyName">属性名</param>
28+
/// <param name="propertyValue">属性值</param>
29+
ILog<TCategoryName> Property(string propertyName, string propertyValue);
30+
31+
/// <summary>
32+
/// 设置日志状态对象
33+
/// </summary>
34+
/// <param name="state">状态对象</param>
35+
ILog<TCategoryName> State(object state);
36+
37+
/// <summary>
38+
/// 设置日志消息
39+
/// </summary>
40+
/// <param name="message">日志消息</param>
41+
/// <param name="args">日志消息参数</param>
42+
ILog<TCategoryName> Message(string message, params object[] args);
43+
44+
/// <summary>
45+
/// 是否启用
46+
/// </summary>
47+
/// <param name="logLevel">日志级别</param>
48+
/// <returns>true=启用;false=禁用</returns>
49+
bool IsEnabled(LogLevel logLevel);
50+
51+
/// <summary>
52+
/// 开启日志范围
53+
/// </summary>
54+
/// <typeparam name="TState">日志状态类型</typeparam>
55+
/// <param name="state">日志状态</param>
56+
IDisposable BeginScope<TState>(TState state);
57+
58+
/// <summary>
59+
/// 写跟踪日志
60+
/// </summary>
61+
ILog<TCategoryName> LogTrace();
62+
63+
/// <summary>
64+
/// 写调试日志
65+
/// </summary>
66+
ILog<TCategoryName> LogDebug();
67+
68+
/// <summary>
69+
/// 写信息日志
70+
/// </summary>
71+
ILog<TCategoryName> LogInformation();
72+
73+
/// <summary>
74+
/// 写警告日志
75+
/// </summary>
76+
ILog<TCategoryName> LogWarning();
77+
78+
/// <summary>
79+
/// 写错误日志
80+
/// </summary>
81+
ILog<TCategoryName> LogError();
82+
83+
/// <summary>
84+
/// 写致命日志
85+
/// </summary>
86+
ILog<TCategoryName> LogCritical();
87+
}
88+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Bing.Logging
2+
{
3+
/// <summary>
4+
/// 日志上下文访问器
5+
/// </summary>
6+
public interface ILogContextAccessor
7+
{
8+
/// <summary>
9+
/// 日志上下文
10+
/// </summary>
11+
LogContext Context { get; set; }
12+
}
13+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System;
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Bing.Logging
5+
{
6+
/// <summary>
7+
/// 日志记录包装器
8+
/// </summary>
9+
/// <typeparam name="TCategoryName">日志类别</typeparam>
10+
public interface ILoggerWrapper<out TCategoryName>
11+
{
12+
/// <summary>
13+
/// 是否启用
14+
/// </summary>
15+
/// <param name="logLevel">日志级别</param>
16+
bool IsEnabled(LogLevel logLevel);
17+
18+
/// <summary>
19+
/// 写日志
20+
/// </summary>
21+
/// <typeparam name="TState">日志状态类型</typeparam>
22+
/// <param name="logLevel">日志级别</param>
23+
/// <param name="eventId">日志事件标识</param>
24+
/// <param name="state">日志状态</param>
25+
/// <param name="exception">异常</param>
26+
/// <param name="formatter">消息格式化操作</param>
27+
void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter);
28+
29+
/// <summary>
30+
/// 开启日志范围
31+
/// </summary>
32+
/// <typeparam name="TState">日志状态类型</typeparam>
33+
/// <param name="state">日志状态</param>
34+
IDisposable BeginScope<TState>(TState state);
35+
36+
/// <summary>
37+
/// 写跟踪日志
38+
/// </summary>
39+
/// <param name="eventId">日志事件标识</param>
40+
/// <param name="exception">异常</param>
41+
/// <param name="message">日志消息</param>
42+
/// <param name="args">日志消息参数</param>
43+
void LogTrace(EventId eventId, Exception exception, string message, params object[] args);
44+
45+
/// <summary>
46+
/// 写调试日志
47+
/// </summary>
48+
/// <param name="eventId">日志事件标识</param>
49+
/// <param name="exception">异常</param>
50+
/// <param name="message">日志消息</param>
51+
/// <param name="args">日志消息参数</param>
52+
void LogDebug(EventId eventId, Exception exception, string message, params object[] args);
53+
54+
/// <summary>
55+
/// 写信息日志
56+
/// </summary>
57+
/// <param name="eventId">日志事件标识</param>
58+
/// <param name="exception">异常</param>
59+
/// <param name="message">日志消息</param>
60+
/// <param name="args">日志消息参数</param>
61+
void LogInformation(EventId eventId, Exception exception, string message, params object[] args);
62+
63+
/// <summary>
64+
/// 写警告日志
65+
/// </summary>
66+
/// <param name="eventId">日志事件标识</param>
67+
/// <param name="exception">异常</param>
68+
/// <param name="message">日志消息</param>
69+
/// <param name="args">日志消息参数</param>
70+
void LogWarning(EventId eventId, Exception exception, string message, params object[] args);
71+
72+
/// <summary>
73+
/// 写错误日志
74+
/// </summary>
75+
/// <param name="eventId">日志事件标识</param>
76+
/// <param name="exception">异常</param>
77+
/// <param name="message">日志消息</param>
78+
/// <param name="args">日志消息参数</param>
79+
void LogError(EventId eventId, Exception exception, string message, params object[] args);
80+
81+
/// <summary>
82+
/// 写致命日志
83+
/// </summary>
84+
/// <param name="eventId">日志事件标识</param>
85+
/// <param name="exception">异常</param>
86+
/// <param name="message">日志消息</param>
87+
/// <param name="args">日志消息参数</param>
88+
void LogCritical(EventId eventId, Exception exception, string message, params object[] args);
89+
}
90+
}

0 commit comments

Comments
 (0)