瀏覽代碼

升级替换Furion内置日志

zuohuaijun 3 年之前
父節點
當前提交
8c9cd6fc9c

+ 4 - 9
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -20,10 +20,9 @@
 
   <ItemGroup>
     <PackageReference Include="Caching.CSRedis" Version="3.8.3" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="3.8.9" />
-    <PackageReference Include="Furion.Extras.Logging.Serilog" Version="3.8.9" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="3.8.9" />
-    <PackageReference Include="Furion.Pure" Version="3.8.9" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="3.9.0" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="3.9.0" />
+    <PackageReference Include="Furion.Pure" Version="3.9.0" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.6.4" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.7" />
     <PackageReference Include="MySql.Data" Version="8.0.29" />
@@ -39,9 +38,5 @@
   <ItemGroup>
     <Folder Include="Service\File\" />
   </ItemGroup>
-
-  <ItemGroup>
-    <ProjectReference Include="..\..\..\OpenSource\Furion\framework\Furion.Pure\Furion.Pure.csproj" />
-  </ItemGroup>
-
+	
 </Project>

+ 2 - 2
Admin.NET/Admin.NET.Core/Filter/LogExceptionHandler.cs

@@ -1,4 +1,4 @@
-using Serilog;
+using Furion.Logging.Extensions;
 
 namespace Admin.NET.Core;
 
@@ -31,6 +31,6 @@ public class LogExceptionHandler : IGlobalExceptionHandler, ISingleton
         });
 
         // 写日志文件
-        Log.Error(stackTrace.ToString());
+        stackTrace.ToString().LogError();
     }
 }

+ 12 - 3
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -4,10 +4,10 @@ using Microsoft.AspNetCore.Builder;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Hosting;
+using Microsoft.Extensions.Logging;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Serialization;
 using OnceMi.AspNetCore.OSS;
-using Serilog;
 using Yitter.IdGenerator;
 
 namespace Admin.NET.Web.Core;
@@ -72,6 +72,16 @@ public class Startup : AppStartup
 
         // 增加Logo输出显示
         services.AddLogoDisplay();
+
+        // 注册日志
+        services.AddFileLogging();
+        services.AddFileLogging("logs/error.log", options =>
+        {
+            options.WriteFilter = (logMsg) =>
+            {
+                return logMsg.LogLevel == LogLevel.Error;
+            };
+        });
     }
 
     public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
@@ -92,8 +102,7 @@ public class Startup : AppStartup
         app.UseHttpsRedirection();
         app.UseStaticFiles();
 
-        // Serilog请求日志中间件---必须在 UseStaticFiles 和 UseRouting 之间
-        app.UseSerilogRequestLogging();
+        app.UseHttpLogging();
 
         app.UseRouting();
 

+ 1 - 2
Admin.NET/Admin.NET.Web.Entry/Program.cs

@@ -1,2 +1 @@
-Serve.Run(RunOptions.Default
-    .ConfigureBuilder(builder => builder.Host.UseSerilogDefault()));
+Serve.Run(RunOptions.Default);

+ 9 - 0
Admin.NET/Admin.NET.Web.Entry/appsettings.Development.json

@@ -6,6 +6,15 @@
       "Default": "Information",
       "Microsoft": "Warning",
       "Microsoft.Hosting.Lifetime": "Information"
+    },
+    "File": {
+      "FileName": "logs/info.log",
+      "FileNameRule": "{0:yyyyMMdd}",
+      "Append": true,
+      "MinimumLevel": "Information",
+      "FileSizeLimitBytes": 5120,
+      "MaxRollingFiles": 100,
+      "UseUtcTimestamp": false
     }
   }
 }

+ 41 - 24
Admin.NET/Admin.NET.Web.Entry/appsettings.json

@@ -3,32 +3,49 @@
 
   "Urls": "https://*:5005",
 
-  "Serilog": {
-    "MinimumLevel": {
+  "Logging": {
+    "LogLevel": {
       "Default": "Information",
-      "Override": {
-        "System": "Warning",
-        "Microsoft": "Warning",
-        "Microsoft.Hosting.Lifetime": "Information",
-        "Microsoft.EntityFrameworkCore": "Information"
-      }
+      "Microsoft": "Warning",
+      "Microsoft.Hosting.Lifetime": "Information"
     },
-    "WriteTo": [
-      {
-        "Name": "Console",
-        "Args": {
-          "outputTemplate": "【时间】{Timestamp:yyyy-MM-dd HH:mm:ss,fff}{NewLine}【等级】{Level:u3}{NewLine}【消息】{Message:lj}{NewLine}{NewLine}"
-        }
-      },
-      {
-        "Name": "File",
-        "Args": {
-          "path": "logs/.log",
-          "rollingInterval": "Day",
-          "outputTemplate": "【时间】{Timestamp:yyyy-MM-dd HH:mm:ss,fff}{NewLine}【等级】{Level:u3}{NewLine}【消息】{Message:lj}{NewLine}{NewLine}"
-        }
-      }
-    ]
+    "File": {
+      "FileName": "logs/info.log",
+      "FileNameRule": "{0:yyyyMMdd}",
+      "Append": true,
+      "MinimumLevel": "Information",
+      "FileSizeLimitBytes": 5120,
+      "MaxRollingFiles": 100,
+      "UseUtcTimestamp": false
+    }
   },
   "AllowedHosts": "*"
+
+  //"Serilog": {
+  //  "MinimumLevel": {
+  //    "Default": "Information",
+  //    "Override": {
+  //      "System": "Warning",
+  //      "Microsoft": "Warning",
+  //      "Microsoft.Hosting.Lifetime": "Information",
+  //      "Microsoft.EntityFrameworkCore": "Information"
+  //    }
+  //  },
+  //  "WriteTo": [
+  //    {
+  //      "Name": "Console",
+  //      "Args": {
+  //        "outputTemplate": "【时间】{Timestamp:yyyy-MM-dd HH:mm:ss,fff}{NewLine}【等级】{Level:u3}{NewLine}【消息】{Message:lj}{NewLine}{NewLine}"
+  //      }
+  //    },
+  //    {
+  //      "Name": "File",
+  //      "Args": {
+  //        "path": "logs/.log",
+  //        "rollingInterval": "Day",
+  //        "outputTemplate": "【时间】{Timestamp:yyyy-MM-dd HH:mm:ss,fff}{NewLine}【等级】{Level:u3}{NewLine}【消息】{Message:lj}{NewLine}{NewLine}"
+  //      }
+  //    }
+  //  ]
+  //},
 }