diff --git a/src/Admin/ThingsGateway.Admin.Application/Filter/RequestAuditFilter.cs b/src/Admin/ThingsGateway.Admin.Application/Filter/RequestAuditFilter.cs index 7a7dd2f09..b4f449e06 100644 --- a/src/Admin/ThingsGateway.Admin.Application/Filter/RequestAuditFilter.cs +++ b/src/Admin/ThingsGateway.Admin.Application/Filter/RequestAuditFilter.cs @@ -251,11 +251,13 @@ public class RequestAuditFilter : IAsyncActionFilter, IOrderedFilter if (exception == null) { - logger.Log(LogLevel.Information, $"{logData.Method}:{logData.Path}-{logData.Operation}"); + if (logger.IsEnabled(LogLevel.Information)) + logger.Log(LogLevel.Information, $"{logData.Method}:{logData.Path}-{logData.Operation}"); } else { - logger.Log(LogLevel.Warning, $"{logData.Method}:{logData.Path}-{logData.Operation}{Environment.NewLine}{logData.Exception?.ToSystemTextJsonString()}{Environment.NewLine}{logData.Validation?.ToSystemTextJsonString()}"); + if (logger.IsEnabled(LogLevel.Warning)) + logger.Log(LogLevel.Warning, $"{logData.Method}:{logData.Path}-{logData.Operation}{Environment.NewLine}{logData.Exception?.ToSystemTextJsonString()}{Environment.NewLine}{logData.Validation?.ToSystemTextJsonString()}"); } } diff --git a/src/Admin/ThingsGateway.Common/Localization/Json/JsonStringLocalizer.cs b/src/Admin/ThingsGateway.Common/Localization/Json/JsonStringLocalizer.cs index b53dcc527..3605df2cb 100644 --- a/src/Admin/ThingsGateway.Common/Localization/Json/JsonStringLocalizer.cs +++ b/src/Admin/ThingsGateway.Common/Localization/Json/JsonStringLocalizer.cs @@ -66,7 +66,8 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba } catch (Exception ex) { - Logger.LogError(ex, "{JsonStringLocalizerName} searched for '{Name}' in '{typeName}' with culture '{CultureName}' throw exception.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); + if (Logger?.IsEnabled(LogLevel.Error) == true) + Logger.LogError(ex, "{JsonStringLocalizerName} searched for '{Name}' in '{typeName}' with culture '{CultureName}' throw exception.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); } return ret; } @@ -176,7 +177,8 @@ internal class JsonStringLocalizer(Assembly assembly, string typeName, string ba localizationMissingItemHandler.HandleMissingItem(name, typeName, CultureInfo.CurrentUICulture.Name); if (jsonLocalizationOptions.IgnoreLocalizerMissing == false) { - Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); + if (Logger?.IsEnabled(LogLevel.Information) == true) + Logger.LogInformation("{JsonStringLocalizerName} searched for '{Name}' in '{TypeName}' with culture '{CultureName}' not found.", nameof(JsonStringLocalizer), name, typeName, CultureInfo.CurrentUICulture.Name); } _missingManifestCache.TryAdd($"name={name}&culture={CultureInfo.CurrentUICulture.Name}"); } diff --git a/src/Admin/ThingsGateway.Furion/EventBus/HostedServices/EventBusHostedService.cs b/src/Admin/ThingsGateway.Furion/EventBus/HostedServices/EventBusHostedService.cs index 4b13b9918..0c6ee8a05 100644 --- a/src/Admin/ThingsGateway.Furion/EventBus/HostedServices/EventBusHostedService.cs +++ b/src/Admin/ThingsGateway.Furion/EventBus/HostedServices/EventBusHostedService.cs @@ -295,7 +295,8 @@ internal sealed class EventBusHostedService : BackgroundService , retryAction: (total, times) => { // 输出重试日志 - _logger.LogWarning("Retrying {times}/{total} times for {EventId}", times, total, eventSource.EventId); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning) == true) + _logger.LogWarning("Retrying {times}/{total} times for {EventId}", times, total, eventSource.EventId); }).ConfigureAwait(false); } else diff --git a/src/Admin/ThingsGateway.Furion/Schedule/HostedServices/ScheduleHostedService.cs b/src/Admin/ThingsGateway.Furion/Schedule/HostedServices/ScheduleHostedService.cs index fea5aab0c..d0a7c7ff7 100644 --- a/src/Admin/ThingsGateway.Furion/Schedule/HostedServices/ScheduleHostedService.cs +++ b/src/Admin/ThingsGateway.Furion/Schedule/HostedServices/ScheduleHostedService.cs @@ -369,11 +369,13 @@ internal sealed class ScheduleHostedService : BackgroundService // 写入作业执行详细日志 if (executionException == null) { - jobLogger?.LogInformation("{jobExecutingContext}", jobExecutingContext); + if (jobLogger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information) == true) + jobLogger?.LogInformation("{jobExecutingContext}", jobExecutingContext); } else { - jobLogger?.LogError(executionException, "{jobExecutingContext}", jobExecutingContext); + if (jobLogger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error) == true) + jobLogger?.LogError(executionException, "{jobExecutingContext}", jobExecutingContext); } // 记录作业触发器运行信息 diff --git a/src/Admin/ThingsGateway.Furion/V5_Experience/HttpRemote/Delegates/ProfilerDelegatingHandler.cs b/src/Admin/ThingsGateway.Furion/V5_Experience/HttpRemote/Delegates/ProfilerDelegatingHandler.cs index 1be087b37..c07905dee 100644 --- a/src/Admin/ThingsGateway.Furion/V5_Experience/HttpRemote/Delegates/ProfilerDelegatingHandler.cs +++ b/src/Admin/ThingsGateway.Furion/V5_Experience/HttpRemote/Delegates/ProfilerDelegatingHandler.cs @@ -251,7 +251,8 @@ public sealed class ProfilerDelegatingHandler(ILogger logger, IOptions< // 检查是否配置(注册)了日志程序 if (remoteOptions.IsLoggingRegistered) { - logger.Log(remoteOptions.ProfilerLogLevel, "{message}", message); + if (logger?.IsEnabled(remoteOptions.ProfilerLogLevel) == true) + logger.Log(remoteOptions.ProfilerLogLevel, "{message}", message); } else { diff --git a/src/Admin/ThingsGateway.SqlSugar/Sugar/IntegrationServices/SerializeService.cs b/src/Admin/ThingsGateway.SqlSugar/Sugar/IntegrationServices/SerializeService.cs index aefe76dae..84ae21c81 100644 --- a/src/Admin/ThingsGateway.SqlSugar/Sugar/IntegrationServices/SerializeService.cs +++ b/src/Admin/ThingsGateway.SqlSugar/Sugar/IntegrationServices/SerializeService.cs @@ -57,6 +57,7 @@ namespace ThingsGateway.SqlSugar } }); + _systemTextJsonSettings.NumberHandling = JsonNumberHandling.AllowNamedFloatingPointLiterals; _systemTextJsonSettings.Converters.Add(new JTokenSystemTextJsonConverter()); _systemTextJsonSettings.Converters.Add(new JValueSystemTextJsonConverter()); _systemTextJsonSettings.Converters.Add(new JObjectSystemTextJsonConverter()); diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 3f755830d..243faf8ff 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,9 +1,9 @@ - 10.11.104 - 10.11.104 - 10.11.104 + 10.11.105 + 10.11.105 + 10.11.105 10.11.6 10.11.6 8.0.21 diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Management/ManagementTask.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Management/ManagementTask.cs index 7bc770a38..29f0f5dd7 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Management/ManagementTask.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Management/ManagementTask.cs @@ -117,6 +117,7 @@ public partial class ManagementTask : AsyncDisposableObject { b.UseSystemTextJson(json => { + json.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; json.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson()); json.Converters.Add(new JTokenSystemTextJsonConverter()); json.Converters.Add(new JValueSystemTextJsonConverter()); @@ -180,6 +181,7 @@ public partial class ManagementTask : AsyncDisposableObject { b.UseSystemTextJson(json => { + json.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; json.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson()); json.Converters.Add(new JTokenSystemTextJsonConverter()); json.Converters.Add(new JValueSystemTextJsonConverter()); diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Redundant/RedundancyTask.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Redundant/RedundancyTask.cs index b36cc91a3..b20dc8950 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Redundant/RedundancyTask.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Management/Redundant/RedundancyTask.cs @@ -350,6 +350,7 @@ internal sealed class RedundancyTask : IRpcDriver, IAsyncDisposable { b.UseSystemTextJson(json => { + json.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; json.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson()); json.Converters.Add(new JTokenSystemTextJsonConverter()); json.Converters.Add(new JValueSystemTextJsonConverter()); @@ -394,6 +395,9 @@ internal sealed class RedundancyTask : IRpcDriver, IAsyncDisposable { b.UseSystemTextJson(json => { + + + json.NumberHandling = System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals; json.Converters.Add(new ByteArrayToNumberArrayConverterSystemTextJson()); json.Converters.Add(new JTokenSystemTextJsonConverter()); json.Converters.Add(new JValueSystemTextJsonConverter()); diff --git a/src/Gateway/ThingsGateway.Gateway.Application/Services/Plugin/PluginService.cs b/src/Gateway/ThingsGateway.Gateway.Application/Services/Plugin/PluginService.cs index c579de3e3..a41bd5260 100644 --- a/src/Gateway/ThingsGateway.Gateway.Application/Services/Plugin/PluginService.cs +++ b/src/Gateway/ThingsGateway.Gateway.Application/Services/Plugin/PluginService.cs @@ -136,7 +136,8 @@ internal sealed class PluginService : IPluginService if (driverType != null) { var driver = (DriverBase)Activator.CreateInstance(driverType); - _logger?.LogInformation(string.Format(AppResource.LoadTypeSuccess, pluginName)); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information) == true) + _logger?.LogInformation(string.Format(AppResource.LoadTypeSuccess, pluginName)); _driverBaseDict.TryAdd(pluginName, driverType); return driver; } @@ -440,7 +441,8 @@ internal sealed class PluginService : IPluginService catch (Exception ex) { // 加载失败时记录警告信息 - _logger?.LogWarning(ex, string.Format(AppResource.LoadOtherFileFail, item)); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning) == true) + _logger?.LogWarning(ex, string.Format(AppResource.LoadOtherFileFail, item)); } } } @@ -679,7 +681,8 @@ internal sealed class PluginService : IPluginService } //添加到全局对象 _assemblyLoadContextDict.TryAdd(fileName, (assemblyLoadContext, assembly)); - _logger?.LogInformation(string.Format(AppResource.AddPluginFile, path)); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information) == true) + _logger?.LogInformation(string.Format(AppResource.AddPluginFile, path)); } return assembly; } @@ -728,7 +731,8 @@ internal sealed class PluginService : IPluginService } catch (Exception ex) { - _logger?.LogWarning(ex, string.Format(AppResource.LoadOtherFileFail, item)); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning) == true) + _logger?.LogWarning(ex, string.Format(AppResource.LoadOtherFileFail, item)); } } } @@ -827,7 +831,8 @@ internal sealed class PluginService : IPluginService { //添加到字典 _driverBaseDict.TryAdd($"{driverMainName}.{type.Name}", type); - _logger?.LogInformation(string.Format(AppResource.LoadTypeSuccess, PluginInfoUtil.GetFullName(driverMainName, type.Name))); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Information) == true) + _logger?.LogInformation(string.Format(AppResource.LoadTypeSuccess, PluginInfoUtil.GetFullName(driverMainName, type.Name))); } var plugin = new PluginInfo() { @@ -847,7 +852,8 @@ internal sealed class PluginService : IPluginService catch (Exception ex) { // 记录加载插件失败的日志 - _logger?.LogWarning(ex, string.Format(AppResource.LoadPluginFail, Path.GetRelativePath(AppContext.BaseDirectory.CombinePathWithOs(tempDir), folderPath))); + if (_logger?.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Warning) == true) + _logger?.LogWarning(ex, string.Format(AppResource.LoadPluginFail, Path.GetRelativePath(AppContext.BaseDirectory.CombinePathWithOs(tempDir), folderPath))); } } return plugins.DistinctBy(a => a.FullName).OrderBy(a => a.EducationPlugin);