change - 日志框架修改

master
wenjy 2 months ago
parent 44abaa36c4
commit 1bcc0aaa89

@ -78,6 +78,26 @@ namespace SlnMesnac.Config
/// </summary> /// </summary>
public string redisConfig { get; set; } public string redisConfig { get; set; }
/// <summary>
/// 相机网络地址
/// </summary>
public string cameraIp { get; set; }
/// <summary>
/// 相机端口
/// </summary>
public int cameraPort { get; set; }
/// <summary>
/// 相机用户名
/// </summary>
public string cameraUserName { get; set; }
/// <summary>
/// 相机密码
/// </summary>
public string cameraPassword { get; set; }
public AppConfig Value => this; public AppConfig Value => this;
} }
} }

@ -1,5 +1,6 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Quartz; using Quartz;
using SlnMesnac.Serilog;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
@ -31,16 +32,17 @@ namespace SlnMesnac.Quartz.Job
{ {
public class MyJob : IJob public class MyJob : IJob
{ {
private readonly ILogger<MyJob> _logger;
public MyJob(ILogger<MyJob> logger) public readonly SerilogHelper _logger;
public MyJob(SerilogHelper logger)
{ {
_logger = logger; _logger = logger;
} }
public Task Execute(IJobExecutionContext context) public Task Execute(IJobExecutionContext context)
{ {
_logger.LogInformation($"执行MyJob{DateTime.Now.ToString("HH:mm:ss")}"); _logger.Info($"执行MyJob{DateTime.Now.ToString("HH:mm:ss")}");
return Task.CompletedTask; return Task.CompletedTask;
} }
} }

@ -40,9 +40,9 @@ namespace SlnMesnac.Quartz
trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例每3s执行一次 trigger.WithCronSchedule("*/3 * * * * ?").WithIdentity("MyJob", "MyJobGroup") // 示例每3s执行一次
); );
q.ScheduleJob<Job2>(trigger => //q.ScheduleJob<Job2>(trigger =>
trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例每5s执行一次 // trigger.WithCronSchedule("*/5 * * * * ?").WithIdentity("Job2", "Job2Group") // 示例每5s执行一次
); //);
}); });
services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true); services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);

@ -10,4 +10,8 @@
<PackageReference Include="Quartz.AspNetCore" Version="3.8.0" /> <PackageReference Include="Quartz.AspNetCore" Version="3.8.0" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SlnMesnac.Serilog\SlnMesnac.Serilog.csproj" />
</ItemGroup>
</Project> </Project>

@ -42,7 +42,8 @@ namespace SlnMesnac.Serilog
#region 通过配置文件读取日志存放位置 #region 通过配置文件读取日志存放位置
var appConfig = app.ApplicationServices.GetService<AppConfig>(); var appConfig = app.ApplicationServices.GetService<AppConfig>();
var logPath = $"{appConfig.logPath}/Logs/{DateTime.UtcNow:yyyy-MM-dd}/"; var logPath = $"{appConfig.logPath}/Logs/";
#endregion #endregion
//Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() //Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
@ -55,16 +56,16 @@ namespace SlnMesnac.Serilog
Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console() Log.Logger = new LoggerConfiguration().MinimumLevel.Information().WriteTo.Console()
.WriteTo.Logger(lc => lc .WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info")) .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Info"))
.WriteTo.File(Path.Combine(logPath, "Info.log"))) .WriteTo.File(Path.Combine($"{logPath}/Info/", "Info.log"),rollingInterval:RollingInterval.Day))
.WriteTo.Logger(lc => lc .WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc")) .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Plc"))
.WriteTo.File(Path.Combine(logPath, "Plc.log"))) .WriteTo.File(Path.Combine($"{logPath}/Plc/", "Plc.log"), rollingInterval: RollingInterval.Day))
.WriteTo.Logger(lc => lc .WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Camera")) .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Camera"))
.WriteTo.File(Path.Combine(logPath, "Camera.log"))) .WriteTo.File(Path.Combine($"{logPath}/Camera/", "Camera.log"), rollingInterval: RollingInterval.Day))
.WriteTo.Logger(lc => lc .WriteTo.Logger(lc => lc
.Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error")) .Filter.ByIncludingOnly(logEvent => logEvent.Properties.ContainsKey("Module") && logEvent.Properties["Module"].ToString().Contains("Error"))
.WriteTo.File(Path.Combine(logPath, "Error.log"))) .WriteTo.File(Path.Combine($"{logPath}/Error/", "Error.log"), rollingInterval: RollingInterval.Day))
.CreateLogger(); .CreateLogger();
app.UseSerilogRequestLogging(); app.UseSerilogRequestLogging();

@ -6,6 +6,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<PackageIcon></PackageIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

@ -9,7 +9,7 @@ using Autofac;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using SlnMesnac.Ioc; using SlnMesnac.Ioc;
using SlnMesnac.Extensions; using SlnMesnac.Extensions;
using SlnMesnac.TouchSocket; using SlnMesnac.Quartz;
namespace SlnMesnac.WPF namespace SlnMesnac.WPF
{ {
@ -41,6 +41,7 @@ namespace SlnMesnac.WPF
//注册PLC工厂 //注册PLC工厂
services.AddPlcFactorySetup(); services.AddPlcFactorySetup();
//services.AddQuartzSetUp();
} }
/// <summary> /// <summary>

@ -55,12 +55,14 @@ namespace SlnMesnac.WPF.ViewModel
public Int32 Scenery_RealHandle = -1; public Int32 Scenery_RealHandle = -1;
public Int32 Thermal_RealHandle = -1; public Int32 Thermal_RealHandle = -1;
private const string DVRIPAddress = "192.168.1.64"; //设备IP地址或者域名 Device IP //private const string DVRIPAddress = "192.168.2.64"; //设备IP地址或者域名 Device IP
private const Int16 DVRPortNumber = 8000; //设备服务端口号 Device Port //private const Int16 DVRPortNumber = 8000; //设备服务端口号 Device Port
private const string DVRUserName = "admin"; //设备登录用户名 User name to login //private const string DVRUserName = "admin"; //设备登录用户名 User name to login
private const string DVRPassword = "haiwei@2024"; //设备登录密码 Password to login //private const string DVRPassword = "haiwei@2024"; //设备登录密码 Password to login
public IndexControlViewModel() public IndexControlViewModel()
{
try
{ {
_log = App.ServiceProvider.GetService<SerilogHelper>(); _log = App.ServiceProvider.GetService<SerilogHelper>();
_callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback); _callback = new CHCNetSDK.RemoteConfigCallback(GetThermInfoCallback);
@ -71,6 +73,11 @@ namespace SlnMesnac.WPF.ViewModel
autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture; autoModeBusiness.CaptureAlarmPictureEvent += CapturePicture;
RefreshTrackMotorAddress(); RefreshTrackMotorAddress();
}catch (Exception ex)
{
_log.Error("巡检控制系统初始化失败",ex);
MessageBox.Show($"巡检控制系统初始化失败:{ex.Message}");
}
} }
#region 参数定义 #region 参数定义
@ -115,7 +122,7 @@ namespace SlnMesnac.WPF.ViewModel
} }
m_lUserID = CHCNetSDK.NET_DVR_Login_V30(DVRIPAddress, DVRPortNumber, DVRUserName, DVRPassword, ref DeviceInfo); m_lUserID = CHCNetSDK.NET_DVR_Login_V30(_appConfig.cameraIp, _appConfig.cameraPort, _appConfig.cameraUserName, _appConfig.cameraPassword, ref DeviceInfo);
if (m_lUserID < 0) if (m_lUserID < 0)
{ {
@ -168,11 +175,15 @@ namespace SlnMesnac.WPF.ViewModel
public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData) public void GetThermInfoCallback(uint dwType, IntPtr lpBuffer, uint dwBufLen, IntPtr pUserData)
{ {
var ret = Marshal.PtrToStructure<CHCNetSDK.NET_DVR_THERMOMETRY_UPLOAD>(lpBuffer); var ret = Marshal.PtrToStructure<CHCNetSDK.NET_DVR_THERMOMETRY_UPLOAD>(lpBuffer);
if (autoModeBusiness != null)
{
autoModeBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1); autoModeBusiness._realTemperatureInfo.fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1);
autoModeBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature); autoModeBusiness._realTemperatureInfo.fMinTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMinTemperature);
autoModeBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1); autoModeBusiness._realTemperatureInfo.fAverageTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fAverageTemperature, 1);
autoModeBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1); autoModeBusiness._realTemperatureInfo.fTemperatureDiff = (float)Math.Round(ret.struLinePolygonThermCfg.fTemperatureDiff, 1);
}
this.RealTemperature = new RealTemperatureInfo() this.RealTemperature = new RealTemperatureInfo()
{ {
fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1), fMaxTemperature = (float)Math.Round(ret.struLinePolygonThermCfg.fMaxTemperature, 1),

@ -12,6 +12,10 @@
"visibleRangePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\可见光图像", "visibleRangePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\可见光图像",
"infraredImagePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\红外热成像", "infraredImagePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\红外热成像",
"videoFilePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\巡检录像", "videoFilePath": "F:\\桌面\\赛轮智慧热电项目\\日志信息\\巡检录像",
"cameraIp": "192.168.2.64",
"cameraPort": 8000,
"cameraUserName": "admin",
"cameraPassword": "haiwei@2024",
"checkCycle": 5, "checkCycle": 5,
"SqlConfig": [ "SqlConfig": [
{ {

Loading…
Cancel
Save