Explorar o código

完善日志分类(消息、警告、错误)

zuohuaijun %!s(int64=3) %!d(string=hai) anos
pai
achega
da34b481c6

+ 2 - 0
Admin.NET/Admin.NET.Application/Service/TestService.cs

@@ -1,6 +1,7 @@
 using Admin.NET.Application.Const;
 using Furion.DatabaseAccessor;
 using Furion.Localization;
+using Furion.Logging.Extensions;
 using Microsoft.AspNetCore.Authorization;
 
 namespace Admin.NET.Application.Serice;
@@ -48,6 +49,7 @@ public class TestService : IDynamicApiController, ITransient
     /// <returns></returns>
     public string TestCulture()
     {
+        "ddd".LogWarning();
         //L.SetCulture("zh-CN");
         //var a = L.GetSelectCulture();
         //var a1 = L.Text["API Interfaces"];

+ 3 - 3
Admin.NET/Admin.NET.Core/Admin.NET.Core.csproj

@@ -25,9 +25,9 @@
   <ItemGroup>
     <PackageReference Include="AspNetCoreRateLimit" Version="4.0.2" />
     <PackageReference Include="Caching.CSRedis" Version="3.8.3" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.0.5" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.0.5" />
-    <PackageReference Include="Furion.Pure" Version="4.0.5" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.0.7" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.0.7" />
+    <PackageReference Include="Furion.Pure" Version="4.0.7" />
     <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" />

+ 28 - 6
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -84,24 +84,46 @@ public class Startup : AppStartup
         // 日志记录
         services.AddLogging(builder =>
         {
-            // 错误级别日志归类
-            builder.AddFile("logs/error.log", options =>
+            // 每天创建一个日志文件(消息日志、错误日志、警告日志)
+            builder.AddFile("logs/{0:yyyyMMdd}_inf.log", options =>
+            {
+                options.WriteFilter = (logMsg) =>
+                {
+                    return logMsg.LogLevel == LogLevel.Information;
+                };
+                options.FileNameRule = fileName =>
+                {
+                    return string.Format(fileName, DateTime.Now);
+                };
+            });
+            builder.AddFile("logs/{0:yyyyMMdd}_err.log", options =>
             {
                 options.WriteFilter = (logMsg) =>
                 {
                     return logMsg.LogLevel == LogLevel.Error;
                 };
+                options.FileNameRule = fileName =>
+                {
+                    return string.Format(fileName, DateTime.Now);
+                };
             });
-            // 每天创建一个日志文件
-            builder.AddFile("logs/{0:yyyyMMdd}.log", options =>
+            builder.AddFile("logs/{0:yyyyMMdd}_wrn.log", options =>
             {
+                options.WriteFilter = (logMsg) =>
+                {
+                    return logMsg.LogLevel == LogLevel.Warning;
+                };
                 options.FileNameRule = fileName =>
                 {
-                    return string.Format(fileName, DateTime.UtcNow);
+                    return string.Format(fileName, DateTime.Now);
                 };
             });
+
             // 日志写入数据库
-            builder.AddDatabase<DbLoggingWriter>();
+            builder.AddDatabase<DbLoggingWriter>(options =>
+            {
+                options.MinimumLevel = LogLevel.Information;
+            });
         });
 
         // 设置雪花Id算法机器码