ソースを参照

增加默认日志过滤、修复long超过16位时精度损失

zuohuaijun 3 年 前
コミット
6fde9dae44

+ 9 - 9
Admin.NET/Admin.NET.Application/Service/TestJobTimer.cs

@@ -16,16 +16,16 @@ public class TestJobTimer : ISpareTimeWorker
     [SpareTime(5000, "定时器", StartNow = true, ExecuteType = SpareTimeExecuteTypes.Serial)]
     public void CollectDeviceChannel(SpareTimer timer, long count)
     {
-        //// 写日志文件
-        //StringLoggingPart.Default.SetMessage("这是一个日志").LogInformation();
+        ////// 写日志文件
+        ////StringLoggingPart.Default.SetMessage("这是一个日志").LogInformation();
 
-        Scoped.Create((_, scope) =>
-        {
-            //var services = scope.ServiceProvider;
-            //var db = services.GetService<ISqlSugarClient>();
+        //Scoped.Create((_, scope) =>
+        //{
+        //    //var services = scope.ServiceProvider;
+        //    //var db = services.GetService<ISqlSugarClient>();
 
-            // 写日志文件
-            Log.Information("【定时器】" + DateTime.Now + "执行次数:" + count);
-        });
+        //    // 写日志文件
+        //    Log.Information("【定时器】" + DateTime.Now + "执行次数:" + count);
+        //});
     }
 }

+ 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.669" />
-    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.4.4" />
-    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.4.4" />
-    <PackageReference Include="Furion.Pure" Version="4.4.4" />
+    <PackageReference Include="Furion.Extras.Authentication.JwtBearer" Version="4.4.5" />
+    <PackageReference Include="Furion.Extras.ObjectMapper.Mapster" Version="4.4.5" />
+    <PackageReference Include="Furion.Pure" Version="4.4.5" />
     <PackageReference Include="Magicodes.IE.Excel" Version="2.6.4" />
     <PackageReference Include="Magicodes.IE.Pdf" Version="2.6.4" />
     <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.9" />

+ 6 - 11
Admin.NET/Admin.NET.Core/Util/LongJsonConverter.cs

@@ -5,21 +5,16 @@ namespace Admin.NET.Core;
 /// <summary>
 /// 序列化时long转string(防止js精度溢出)
 /// </summary>
-public class LongJsonConverter : JsonConverter
+public class LongJsonConverter : JsonConverter<long>
 {
-    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
+    public override void WriteJson(JsonWriter writer, long value, JsonSerializer serializer)
     {
-        JToken jtoken = JValue.ReadFrom(reader);
-        return jtoken.Values();
-    }
-
-    public override bool CanConvert(Type objectType)
-    {
-        return typeof(System.Int64).Equals(objectType);
+        serializer.Serialize(writer, value.ToString());
     }
 
-    public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
+    public override long ReadJson(JsonReader reader, Type objectType, long existingValue, bool hasExistingValue, JsonSerializer serializer)
     {
-        serializer.Serialize(writer, value.ToString());
+        JToken jt = JValue.ReadFrom(reader);
+        return jt.Value<long>();
     }
 }

+ 1 - 1
Admin.NET/Admin.NET.Web.Core/Startup.cs

@@ -49,7 +49,7 @@ public class Startup : AppStartup
                 options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); // 首字母小写(驼峰样式)
                 options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss"; // 时间格式化
                 options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; // 忽略循环引用
-                options.SerializerSettings.Converters.Add(new LongJsonConverter()); // long转string(防止js精度溢出)
+                // options.SerializerSettings.Converters.Add(new LongJsonConverter()); // long转string(防止js精度溢出) 超过16位开启
                 options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; // 忽略空值
             })
             .AddInjectWithUnifyResult<AdminResultProvider>();

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

@@ -1 +1,13 @@
-Serve.Run(RunOptions.Default);
+Serve.Run(RunOptions.Default.AddWebComponent<WebComponent>());
+
+public class WebComponent : IWebComponent
+{
+    public void Load(WebApplicationBuilder builder, ComponentContext componentContext)
+    {
+        // ÈÕÖ¾¹ýÂË
+        builder.Logging.AddFilter((provider, category, logLevel) =>
+        {
+            return !new[] { "Microsoft.Hosting", "Microsoft.AspNetCore" }.Any(u => category.StartsWith(u)) && logLevel >= LogLevel.Information;
+        });
+    }
+}

+ 1 - 2
Admin.NET/Admin.NET.Web.Entry/appsettings.Development.json

@@ -6,8 +6,7 @@
     "Logging": {
         "LogLevel": {
             "Default": "Information",
-            "Microsoft": "Warning",
-            "Microsoft.Hosting.Lifetime": "Information"
+            "Microsoft.AspNetCore": "Warning"
         },
         "File": {
             "Enabled": true, // 启用文件日志

+ 1 - 2
Admin.NET/Admin.NET.Web.Entry/appsettings.json

@@ -6,8 +6,7 @@
     "Logging": {
         "LogLevel": {
             "Default": "Information",
-            "Microsoft": "Warning",
-            "Microsoft.Hosting.Lifetime": "Information"
+            "Microsoft.AspNetCore": "Warning"
         },
         "File": {
             "Enabled": true, // 启用文件日志