优化log等级、json配置注解
This commit is contained in:
@@ -278,7 +278,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
mqttRpcResult = new() { Message = "Failed", RpcId = rpcData.RpcId, Success = false };
|
||||
}
|
||||
try
|
||||
@@ -316,7 +316,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -324,7 +324,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -346,7 +346,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
if (CycleInterval > 500 + 50)
|
||||
|
||||
@@ -184,7 +184,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
mqttRpcResult = new() { Message = "Failed", RpcId = rpcData.RpcId, Success = false };
|
||||
|
||||
}
|
||||
@@ -223,7 +223,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
try
|
||||
@@ -255,7 +255,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -265,7 +265,7 @@ namespace ThingsGateway.Mqtt
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
if (CycleInterval > 500 + 50)
|
||||
{
|
||||
|
||||
@@ -159,7 +159,7 @@ namespace ThingsGateway.OPCDA
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
Device.DeviceStatus = DeviceStatusEnum.OnLineButNoInitialValue;
|
||||
Device.DeviceOffMsg = ex.Message;
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace ThingsGateway.OPCUA
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
Device.DeviceOffMsg = ex.Message;
|
||||
}
|
||||
}
|
||||
@@ -189,7 +189,7 @@ namespace ThingsGateway.OPCUA
|
||||
{
|
||||
if (e.Error)
|
||||
{
|
||||
_logger.LogError(e.Text);
|
||||
_logger.LogWarning(e.Text);
|
||||
Device.DeviceStatus = DeviceStatusEnum.OnLineButNoInitialValue;
|
||||
Device.DeviceOffMsg = $"{e.Text}";
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -194,7 +194,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +204,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
}
|
||||
try
|
||||
{
|
||||
@@ -227,7 +227,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -246,7 +246,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, ToString());
|
||||
_logger.LogWarning(ex, ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -257,7 +257,7 @@ namespace ThingsGateway.RabbitMQ
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, ToString());
|
||||
_logger?.LogWarning(ex, ToString());
|
||||
}
|
||||
|
||||
if (CycleInterval > 500 + 50)
|
||||
|
||||
@@ -14,10 +14,11 @@ namespace ThingsGateway.Core
|
||||
|
||||
public void Load(IServiceCollection services, ComponentContext componentContext)
|
||||
{
|
||||
|
||||
var logFileEnable = App.GetConfig<bool>("LogFileEnable");
|
||||
if (logFileEnable != true) return;
|
||||
//获取默认日志等级
|
||||
var defaultLevel = App.GetConfig<LogLevel?>("Logging:LogLevel:Default");
|
||||
var defaultLevel = App.GetConfig<LogLevel?>("Logging:LogLevel:FileDefault");
|
||||
//获取最大日志等级,默认Error
|
||||
var maxLevel = App.GetConfig<LogLevel?>("Logging:LogLevel:Max") ?? LogLevel.Error;
|
||||
//获取程序根目录
|
||||
@@ -69,6 +70,9 @@ namespace ThingsGateway.Core
|
||||
//如果配置不写入mongitor日志和日志名称为System.Logging.LoggingMonitor
|
||||
if (!WriteMonitor && logMsg.LogName == "System.Logging.LoggingMonitor")
|
||||
return false;
|
||||
if(!logMsg.LogName.StartsWith("System") &&
|
||||
!logMsg.LogName.StartsWith("Microsoft"))
|
||||
{ return false; }
|
||||
return logMsg.LogLevel == logLevel;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
//"Urls": "https://localhost:7101;http://localhost:7100",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Trace",
|
||||
"Custom": "Information",
|
||||
"Console": "Information",
|
||||
"FileDefault": "Information", //程序日志写入文件等级,不包含网关日志
|
||||
"RunTimeLogCustom": "Information", //网关运行日志存入数据库等级,部署推荐Error
|
||||
"Console": "Trace", //控制台输出日志等级
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"LogFileEnable": false,
|
||||
"WriteMonitor": false,
|
||||
"LogFileEnable": true, //程序日志写入文件
|
||||
"WriteMonitor": true, //程序日志是否包含Monitor
|
||||
//动态API设备
|
||||
"DynamicApiControllerSettings": {
|
||||
"LowercaseRoute": false, //是否采用小写路由,bool 类型,默认 true
|
||||
|
||||
@@ -167,7 +167,7 @@ public class AlarmHostService : BackgroundService, ISingleton
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, $"实时报警循环异常");
|
||||
_logger?.LogWarning(ex, $"实时报警循环异常");
|
||||
}
|
||||
}
|
||||
}, StoppingToken.Token
|
||||
@@ -253,7 +253,7 @@ public class AlarmHostService : BackgroundService, ISingleton
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (LastIsSuccess)
|
||||
_logger?.LogError($"历史报警循环异常:" + ex.Message);
|
||||
_logger?.LogWarning($"历史报警循环异常:" + ex.Message);
|
||||
StatuString = new OperResult($"异常:请查看后台日志");
|
||||
LastIsSuccess = false;
|
||||
}
|
||||
|
||||
@@ -265,7 +265,7 @@ public class CollectDeviceCore : DisposableObject
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, $"采集线程循环异常{_device.Name}");
|
||||
_logger?.LogWarning(ex, $"采集线程循环异常{_device.Name}");
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
@@ -274,7 +274,7 @@ public class CollectDeviceCore : DisposableObject
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, $"采集线程循环异常{_device.Name}");
|
||||
_logger?.LogWarning(ex, $"采集线程循环异常{_device.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ public class UploadDeviceCore : DisposableObject
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, $"上传线程循环异常{_device.Name}");
|
||||
_logger?.LogWarning(ex, $"上传线程循环异常{_device.Name}");
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
@@ -185,7 +185,7 @@ public class UploadDeviceCore : DisposableObject
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.LogError(ex, $"上传线程循环异常{_device.Name}");
|
||||
_logger?.LogWarning(ex, $"上传线程循环异常{_device.Name}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ public class ValueHisHostService : BackgroundService, ISingleton
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (LastIsSuccess)
|
||||
_logger?.LogError(ex, $"历史数据循环异常");
|
||||
_logger?.LogWarning(ex, $"历史数据循环异常");
|
||||
StatuString = new OperResult($"异常:请查看后台日志");
|
||||
LastIsSuccess = false;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ThingsGateway.Web.Foundation
|
||||
}
|
||||
public void Write(LogMessage logMsg, bool flush)
|
||||
{
|
||||
var customLevel = App.GetConfig<LogLevel?>("Logging:LogLevel:Custom") ?? LogLevel.Trace;
|
||||
var customLevel = App.GetConfig<LogLevel?>("Logging:LogLevel:RunTimeLogCustom") ?? LogLevel.Trace;
|
||||
if (logMsg.LogLevel >= customLevel)
|
||||
{
|
||||
var logRuntime = new RuntimeLog
|
||||
|
||||
@@ -64,12 +64,13 @@ public class CollectVariableRunTime : CollectDeviceVariable
|
||||
try
|
||||
{
|
||||
data = ReadExpressions.GetExpressionsResult(RawValue);
|
||||
Set(data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Set(value);
|
||||
(Name + " 转换表达式失败:" + ex.Message).LogError();
|
||||
}
|
||||
Set(data);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user