|
@@ -17,6 +17,14 @@ public static class LoggingSetup
|
|
|
/// <param name="services"></param>
|
|
/// <param name="services"></param>
|
|
|
public static void AddLoggingSetup(this IServiceCollection services)
|
|
public static void AddLoggingSetup(this IServiceCollection services)
|
|
|
{
|
|
{
|
|
|
|
|
+ //// 控制台日志格式化
|
|
|
|
|
+ //services.AddConsoleFormatter(options =>
|
|
|
|
|
+ //{
|
|
|
|
|
+ // options.DateFormat = "yyyy-MM-dd HH:mm:ss(zzz) dddd";
|
|
|
|
|
+ // //options.WithTraceId = true;
|
|
|
|
|
+ // //options.WithStackFrame = true;
|
|
|
|
|
+ //});
|
|
|
|
|
+
|
|
|
// 日志监听
|
|
// 日志监听
|
|
|
services.AddMonitorLogging(options =>
|
|
services.AddMonitorLogging(options =>
|
|
|
{
|
|
{
|
|
@@ -24,16 +32,8 @@ public static class LoggingSetup
|
|
|
options.IgnorePropertyTypes = new[] { typeof(byte[]) };
|
|
options.IgnorePropertyTypes = new[] { typeof(byte[]) };
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // 控制台日志格式化
|
|
|
|
|
- services.AddConsoleFormatter(options =>
|
|
|
|
|
- {
|
|
|
|
|
- options.DateFormat = "yyyy-MM-dd HH:mm:ss(zzz) dddd";
|
|
|
|
|
- options.WithTraceId = true;
|
|
|
|
|
- options.WithStackFrame = true;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
// 日志写入文件
|
|
// 日志写入文件
|
|
|
- if (App.GetConfig<bool>("Logging:File:Enabled"))
|
|
|
|
|
|
|
+ if (App.GetConfig<bool>("Logging:File:Enabled"))
|
|
|
{
|
|
{
|
|
|
Array.ForEach(new[] { LogLevel.Information, LogLevel.Warning, LogLevel.Error }, logLevel =>
|
|
Array.ForEach(new[] { LogLevel.Information, LogLevel.Warning, LogLevel.Error }, logLevel =>
|
|
|
{
|
|
{
|
|
@@ -52,7 +52,7 @@ public static class LoggingSetup
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 日志写入数据库
|
|
// 日志写入数据库
|
|
|
- if (App.GetConfig<bool>("Logging:Database:Enabled"))
|
|
|
|
|
|
|
+ if (App.GetConfig<bool>("Logging:Database:Enabled"))
|
|
|
{
|
|
{
|
|
|
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
|
services.AddDatabaseLogging<DatabaseLoggingWriter>(options =>
|
|
|
{
|
|
{
|
|
@@ -67,12 +67,12 @@ public static class LoggingSetup
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 日志写入ElasticSearch
|
|
// 日志写入ElasticSearch
|
|
|
- if (App.GetConfig<bool>("Logging:ElasticSearch:Enabled"))
|
|
|
|
|
|
|
+ if (App.GetConfig<bool>("Logging:ElasticSearch:Enabled"))
|
|
|
{
|
|
{
|
|
|
services.AddDatabaseLogging<ElasticSearchLoggingWriter>(options =>
|
|
services.AddDatabaseLogging<ElasticSearchLoggingWriter>(options =>
|
|
|
{
|
|
{
|
|
|
options.WithTraceId = true; // 显示线程Id
|
|
options.WithTraceId = true; // 显示线程Id
|
|
|
- options.WithStackFrame = true; // 显示程序集
|
|
|
|
|
|
|
+ options.WithStackFrame = true; // 显示程序集
|
|
|
options.IgnoreReferenceLoop = false; // 忽略循环检测
|
|
options.IgnoreReferenceLoop = false; // 忽略循环检测
|
|
|
options.MessageFormat = LoggerFormatter.Json;
|
|
options.MessageFormat = LoggerFormatter.Json;
|
|
|
options.WriteFilter = (logMsg) =>
|
|
options.WriteFilter = (logMsg) =>
|